标签:
#import <Foundation/Foundation.h>
typedef struct{
CGFloat width;
CGFloat height;
}vSize;
int main(int argc, const char * argv[]) {
@autoreleasepool {
//装箱 拆箱
//C的基本类型使用NSNumber(bool char double int float long)
NSNumber *ageNumber = [NSNumber numberWithInt:23];
NSNumber *ageNumber2 = @23;
int age = [ageNumber intValue];
//C的复合类型结构NSValue
/*
表示一个点(x, y)
struct CGPoint {
CGFloat x;
CGFloat y;
};
宽度和高度(width, height)
struct CGSize {
CGFloat width;
CGFloat height;
};
一个视图在界面上的尺寸(矩形区域)
struct CGRect {
CGPoint origin;
CGSize size;
};
*/
//1.如何创建一个CGPoint
CGPoint origin = CGPointMake(10, 10);
//2. 创建一个CGSize
CGSize size = CGSizeMake(200, 300);
//3. 创建一个CGRect
CGRect rect = CGRectMake(10, 10, 200, 300);
CGFloat x = rect.origin.x;
CGFloat y = rect.origin.y;
CGFloat width = rect.size.width;
CGFloat height = rect.size.height;
//对结构体进行封装
NSValue *rectV = [NSValue valueWithRect:rect];
NSValue *pointV = [NSValue valueWithPoint:origin];
NSValue *sizeV = [NSValue valueWithSize:size];
CGRect rect1 = [rectV rectValue];
NSLog(@"%@", rectV);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/damonWq/p/5074098.html