One of the data types Geometry data type (cgpoint,cgsize,cgrect)

Source: Internet
Author: User

// CGPoint 结构体数据原型, 用于声明一个点;

02./* Points. */

03.

04.struct CGPoint {

05.CGFloat x;

06.CGFloat y;

07.};

08.typedef struct CGPoint CGPoint;

09.

10.typedef CGPoint NSPoint;

11.

12.// 用法;

13.

14.// 1. 声明一个CGPoint变量,初始化时赋值方式1;

15.

16.CGPoint point = {12};  //CGPoint是一个结构体类型,不是对象,所以变量前不加‘*‘号;

17.// 另一种初始化变量方式2;

18.CGPoint point2 = {.x = 4, .y = 5};

19.point2.x = 2// 赋值方式3;

20.point2.y = 3;

21.

22.point = CGPointMake(45);  // 赋值方式4;

23.// 输出point的x,y值;

24.NSLog(@"point = %@",NSStringFromCGPoint(point));

25.

26.// 2. 声明一个CGSize变量,初始化时赋值方式1;

27.

28.CGSize size = {45};   //CGSize是一个结构体类型,不是对象,所以变量前不加‘*‘号;

29.// 另一种初始化变量方式2;

30.CGSize size2 = {.width = 4, .height = 5};

31.size2.width = 4// 赋值方式3;

32.size2.height = 5;

33.

34.size = CGSizeMake(45);  // 赋值方式4;

35.// 输出size的width,height值;

36.NSLog(@"size = %@",NSStringFromCGSize(size));

37.

38.// 3. 声明一个CGRect变量,初始化时赋值方式1;

39.

40.CGRect rect = {1245};  //CGRect是一个结构体类型,不是对象,所以变量前不加‘*‘号;

41.// 另一种初始化变量方式2;

42.CGRect rect2 = {.origin.x = 1, .origin.y = 1, .size.width = 4, .size.height = 5};

43.// 赋值方式3;

44.CGRect rect3 = {.origin = {.x = 1, .y = 1}, .size = {.width = 4, .height = 5}};

45.// 或

46.CGRect rect4 = {.origin = {11}, .size = {45}};

47.// 赋值方式4;

48.rect2.origin.x = 1;

49.rect2.origin.y = 2;

50.rect2.size.width = 4;

51.rect2.size.height = 5;

52.// 赋值方式5;

53.rect = CGRectMake(1245);

54.// 输出rect的origin,size值;

55.NSLog(@"rect = %@",NSStringFromCGRect(rect));


One of the data types Geometry data type (cgpoint,cgsize,cgrect)

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.