Frames

A frame rectangle refers to the outline of a view in terms of its parent’s coordinate system. Frames use a CGRect structure, which is defined as part of the Core Graphics framework, as its CG prefix suggests. A CGRect is made up of an origin (a CGPoint, x and y) and a size (a CGSize, width and height). When you create views outside Auto Layout, you normally allocate them and initialize them with a frame. Here’s an example:

CGRect rect = CGRectMake(0.0f, 0.0f, 320.0f, 416.0f); myView = [[UIView alloc] initWithFrame:rect];

Views provide two fundamental CGRect properties, which are closely tied together: frame and bounds. Frames are different from bounds in terms of their coordinate system. Frames are defined ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.