本文共 2374 字,大约阅读时间需要 7 分钟。
#importvoid test(){ //定义一种结构体 struct Date{ int Year; int Month; int Day; }; struct Date d={2013,5,4}; d.Day=5; } void test1(){ //宏定义 typedef struct Date{ int Year; int Month; int Day; } MyDate; MyDate day={2013,1,1}; } void NSRangeTest(){ //NSRange是一个结构体,里面有两个成员,一个位置还有一个表示长度 NSRange range={3,1}; NSRange range1=NSMakeRange(6, 3); NSLog(@"location:%zi",range1.location); //NSRange参数类型是NSUInteger 就是Unsigned long类型 访问的话为@zi NSLog(@"length:%zi",range1.length); //还有一种NSString打印方法 NSString *str=NSStringFromRange(range); NSLog(@"range:%@",str); } void pointTest(){ NSPoint point={10,10}; point=NSMakePoint(11, 11); point=CGPointMake(12, 12);//最常用 CGPoint point1; //NSPoint和CGPoint是等价的 point1.x=11; point1.y=12; NSString *str=NSStringFromPoint(point); NSLog(@"%@",str); NSString *str1=NSStringFromPoint(point1); NSLog(@"point:%@",str1); } void sizeTest(){ //创建一个宽度为10,高度是8的size NSSize size=CGSizeMake(10, 8); size=NSMakeSize(11, 9); size.width=12; size.height=10; NSString *str=NSStringFromSize(size); NSLog(@"size:%@",str); } void rectTest(){ //创建一个左边为多少的长方体 CGRect rect1=CGRectMake(1, 1, 10, 10); NSRect rect=CGRectMake(10, 10, 12, 9); rect.origin.x=11; rect.origin.y=11; rect.size.width=100; rect.size.height=90; NSString *str=NSStringFromRect(rect); NSLog(@"rect:%@",str); NSString *str1=NSStringFromRect(rect1); NSLog(@"rect:%@",str1); } int main(int argc, const char * argv[]) { @autoreleasepool { NSRangeTest(); pointTest(); sizeTest(); rectTest(); } return 0; }
结果:
2013-08-02 15:39:55.662 Foundation1-结构体[1267:303] location:6
2013-08-02 15:39:55.678 Foundation1-结构体[1267:303] length:3
2013-08-02 15:39:55.679 Foundation1-结构体[1267:303] range:{3, 1}
2013-08-02 15:39:55.679 Foundation1-结构体[1267:303] {12, 12}
2013-08-02 15:39:55.679 Foundation1-结构体[1267:303] point:{11, 12}
2013-08-02 15:39:55.680 Foundation1-结构体[1267:303] size:{12, 10}
2013-08-02 15:39:55.680 Foundation1-结构体[1267:303] rect:{
{11, 11}, {100, 90}}2013-08-02 15:39:55.680 Foundation1-结构体[1267:303] rect:{
{1, 1}, {10, 10}}本文转自蓬莱仙羽51CTO博客,原文链接:http://blog.51cto.com/dingxiaowei/1366477,如需转载请自行联系原作者