// 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)