CGRect, CGSize and CGPoint Functions

With an understanding ofC structures, and thedefinitions of CGRect, CGSize and CGPointbehind us, let’s look at a handful of functions for working with these structures.

CGRectMake and NSStringFromCGRect

With CGRectMake we can create a new CGRect structure. The rectangles below have differing starting points, however, each have a width and height of 100. The function NSStringFromCGRect returns a string object that defines the rectangle passed in as a parameter:

Note: The output of all examples are shown in the image at the bottom of this post.

CGRectIntersect

To determine if two rectangles intersect, you can write code as follows:

CGRectInset

If you need to create a rectangle that is either larger or smaller than an existing rectangle, centered on the same point, try CGRectInset:

CGRectFromString

A little more uncommon, is creating rectangles from a string, however, if the need arises:

Functions for CGSize and CGPoint

As you would expect, there are similar functions to those above for working with CGSize and CGPoint:

  • CGSizeMake
  • CGSizeEqualToSize
  • CGPointMake
  • CGPointEqualToPoint

http://iphonedevelopertips.com/c/cgrect-cgsize-and-cgpoint-functions.html

你可能感兴趣的:(html,C++,c,C#)