One of the Data Types in objective-C: cgpoint, cgsize, cgrect)

Source: Internet
Author: User

// CGPoint 结构体数据原型, 用于声明一个点;/* Points. */ struct CGPoint {  CGFloat x;  CGFloat y;};typedef struct CGPoint CGPoint; typedef CGPoint NSPoint;// 用法;        // 1. 声明一个CGPoint变量,初始化时赋值方式1;        CGPoint point = {1, 2};  //CGPoint是一个结构体类型,不是对象,所以变量前不加'*'号;    // 另一种初始化变量方式2;    CGPoint point2 = {.x = 4, .y = 5};    point2.x = 2; // 赋值方式3;    point2.y = 3;        point = CGPointMake(4, 5);  // 赋值方式4;    // 输出point的x,y值;    NSLog(@"point = %@",NSStringFromCGPoint(point));        // 2. 声明一个CGSize变量,初始化时赋值方式1;        CGSize size = {4, 5};   //CGSize是一个结构体类型,不是对象,所以变量前不加'*'号;    // 另一种初始化变量方式2;    CGSize size2 = {.width = 4, .height = 5};    size2.width = 4; // 赋值方式3;    size2.height = 5;        size = CGSizeMake(4, 5);  // 赋值方式4;    // 输出size的width,height值;    NSLog(@"size = %@",NSStringFromCGSize(size));        // 3. 声明一个CGRect变量,初始化时赋值方式1;        CGRect rect = {1, 2, 4, 5};  //CGRect是一个结构体类型,不是对象,所以变量前不加'*'号;    // 另一种初始化变量方式2;    CGRect rect2 = {.origin.x = 1, .origin.y = 1, .size.width = 4, .size.height = 5};    // 赋值方式3;    CGRect rect3 = {.origin = {.x = 1, .y = 1}, .size = {.width = 4, .height = 5}};    // 或    CGRect rect4 = {.origin = {1, 1}, .size = {4, 5}};    // 赋值方式4;    rect2.origin.x = 1;    rect2.origin.y = 2;    rect2.size.width = 4;    rect2.size.height = 5;    // 赋值方式5;    rect = CGRectMake(1, 2, 4, 5);    // 输出rect的origin,size值;    NSLog(@"rect = %@",NSStringFromCGRect(rect));


One of the Data Types in objective-C: cgpoint, cgsize, cgrect)

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.