*Foundation框架里的元素一般都是以“NS”开头
常用的结构体大概有以下几个:
(一般都是用CG开头的)
NSRange(表示范围)(位置和长度)(location length)
NSPoint\CGPoint
NSSize\CGSize
NSRect\CGRect (CGPint CGSize)
一般都是有2种方法(e.g.:CGPointMake或者NSMakePoint,一般用前者)
e.g.:
1.NSrange
@"i love oc" // love的范围
NSRange r1 = {2, 4}; //
NSRange r2 = {.location = 2, .length = 4};
NSRange r3 = NSMakeRange(2, 4); // 一般用这种
NSString *str = @"i love oc";
2. 查找某个字符串在str中的范围
如果找不到,length=0,location=NSNotFound==-1
NSRange range = [str rangeOfString:@"ov"];
NSLog(@"loc = %ld, length=%ld", range.location, range.length);
3.NSPoint\CGPoint:
CGPointZero == CGPointMake(0, 0) 表示原点
比较两个点是否相同(x、y)
BOOL b = CGPointEqualToPoint(CGPointMake(10, 10), CGPointMake(10, 10)); 此函数在(CoreGraphics框架)里
CGPoint p1 = NSMakePoint(10, 10);
NSPoint p2 = CGPointMake(20, 20);// 最常用
4.NSSize\CGSize:
NSSize s2 = NSMakeSize(100, 50);
CGSize s3 = NSMakeSize(200, 60);
5.NSRect\CGRect:
CGRect(CGPint,CGsize)有三种写法:
CGRect r1 = CGRectMake(0, 0, 100, 50);
CGRect r2 = { {0, 0}, {100, 90}};
CGRect r3 = {p1, s2};
或者:CGRect r4 = {CGPointZero, CGSizeMake(100, 90)};
6.把结构题转换为字符串:
NSString *str = NSStringFromPoint(p1);
NSString *str = NSStringFromSize(s3);
NSString *str = NSStringFromRect(r1);