Cgfloat, cgpoint, cgsize, and cgrect in IOS

Source: Internet
Author: User

Cggeometry class defines the structure of geometric elements and functions for operating geometric elements.

1. Data Type:

Cgfloat: basic type of floating point value
Cgpoint: points in a two-dimensional coordinate system
Cgsize: indicates the width and height of a rectangle.
Cgrect: the position and size of a rectangle.

typedef float CGFloat;// 32-bittypedef double CGFloat;// 64-bitstruct CGPoint {    CGFloat x;    CGFloat y;};typedef struct CGPoint CGPoint;struct CGSize {    CGFloat width;    CGFloat height;};typedef struct CGSize CGSize;struct CGRect {    CGPoint origin;    CGSize size;};typedef struct CGRect CGRect;

Note: the height and width of the cgrect data structure can be negative. For example, the origin of a rectangle is [0.0, 0.0] And the size is [10.0, 10.0]. This rectangle is exactly the same as the rectangle where the source is [10.0, 10.0] And the size is [-10.0,-10.0.

2. Use values to create geometric elements

Cgpointmake

Cgrectmake

Cgsizemake

CGPoint CGPointMake (   CGFloat x,   CGFloat y);CGSize CGSizeMake (   CGFloat width,   CGFloat height);CGRect CGRectMake (   CGFloat x,   CGFloat y,   CGFloat width,   CGFloat height);
    CGFloat ten=10.0f;    CGPoint point = CGPointMake(0.0f, 0.0f);    CGSize size = CGSizeMake(10.0f, 10.0f);    CGRect rect = CGRectMake(point.x, point.y, size.width, size.height);    NSLog(@"ten: %f", ten);    NSLog(@"point: %@", NSStringFromCGPoint(point));    NSLog(@"size: %@", NSStringFromCGSize(size));    NSLog(@"rect: %@", NSStringFromCGRect(rect));
Address: http://www.cnblogs.com/chivas/archive/2012/05/16/2504006.html
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.