Various structures and associated functions for 2D geometric primitives.
- iOS 2.0+
- macOS 10.0+
- tvOS 9.0+
- watchOS 2.0+
The data structure
CGPoint represents a point in a two-dimensional coordinate system. The data structure
CGRect represents the location and dimensions of a rectangle. The data structure
CGSize represents the dimensions of width and height.
CGSize structure does not explicitly define the unit of measure for its member quantities. A point’s x- and y-coordinates or a size’s width and height are unitless quantities—whether such measurements are treated as pixels, scale-factor-independent points, texture elements (texels), or some other unit depends on the API using the measurement, and on the context in which that API is used. For example, a
CGRect structure specifying the frame of an
UIView object defines the view’s dimensions in points, not pixels. However, the effects of using a
CGPoint structure in a
CGContext drawing operation depend on the scale factor associated with that context. Where not otherwise specified, you can assume that a
CGSize structure is defined in points, not pixels. (For details, see Drawing and Printing Guide for iOS or High Resolution Guidelines for OS X.)
The height and width stored in a
CGRect data structure can be negative. For example, a rectangle with an origin of
[0 and a size of
[10 is exactly equivalent to a rectangle with an origin of
[10 and a size of
[-10. Your application can standardize a rectangle—that is, ensure that the height and width are stored as positive values—by calling the
CGRect function. All functions described in this reference that take
CGRect data structures as inputs implicitly standardize those rectangles before calculating their results. For this reason, your applications should avoid directly reading and writing the data stored in the
CGRect data structure. Instead, use the functions described here to manipulate rectangles and to retrieve their characteristics.