If you have used any C structs in Objective-C programming for screen alignment or sizing then you have used either CGPoint, CGRect and CGSize.

The Objective-C programming language can appear a little intimidating due to it’s unique syntax. However, once your gain the syntax knowledge it is much less intimidating.

CGRect

CGRect is a C struct used in Objective-C to hold two vectors. A CGSize vector and a CGPoint vector.

If you are not familiar with vectors from trigonometry, then you might want to do some light reading on vector math to get a better idea of the power within a vector.

The structure of CGRect looks similar to this.

typedef struct {

  CGPoint origin;
  CGSize size;

} CGRect;

Having these two vectors within a single structure is really handy when dealing cocos2d programming, screen elements, click areas, swipe and touch gestures.

CGSize

CGSize is is a C struct that stored the width and height of an object. It looks like this:

typedef struct {
  CGFloat width;
  CGFloat height;
} CGSize;

CGPoint

CGPoint is another C struct that stores the location of an x and y coordinate. Or more simply a point. It looks like this:

typedef struct {
  CGFloat x;
  CGFloat y;
} CGPoint;

Accessing a C Struct in Objective-C

In order to access the contents of either CGRect, CGSize or CGPoint you would simply use a dot notation similar to the following code.

CGRect rect = CGRectMake(10, 20, 100, 200);

rect.origin.x; //would return the x location value.
rect.origin.y; //would return the y location value.
rect.size.width // would return the width of the object.
rect.size.height //would return the height of the object.

You can do the same with CGSize and CGPoint.

CGPoint p = CGPointMake(10,20);
CGSize s = CGSizeMake(100,200);

p.x //would return the x location
p.y //would return the y location
s.width //would return the width of the object
s.height //would return the height of the object

Conclusion

Now you know the basics of CGRect, CGSize, and CGPoint. Your well on your way to customizing the positioning your iPhone screen objects.