------Java培训、Android培训、iOS培训、.Net培训、期待与您交流! -------
结构体:
有如下结构体:
NSRange,NSPoint/CGPoint,NSSize/CGSize,NSRect/CGRect
注意点:CG开头的结构体一般属于CoreGraphics框架
1.NSRange(表示范围)
参数:location(位置),length(长度)
eg:
NSRange r1 = {2,3} ; // 表示从2开始,3个长度
NSRange r2 = NSMakeRange(2,4); // 表示从2开始,4个长度 常用此方式 常用
NSRange r3 = {.location=2,length=4};
应用:查找某字符串在字符串str中的范围
eg:
NSRange r3 = [str rangeOfString:@"love"]; // 查找字符串love在str中的范围。
NSLog("location = %d,range =%d",r3.location,r3.range); // 打印出结果
注:如果找不到,则length=0,location=NSNotFound。(NSNotFound是个枚举常量,等于-1)
2.NSPoint/CGPoint(表示点坐标)
CGPoint跨平台。
NSFloat = CGFloat = double
参数:double类型的x和double类型的y
eg:
NSPoint p = NSMakePoint(20,20); // 表示点的x和y坐标
NSPoint p2 = CGPointMake(20,20);
CGPointZero表示原点,相当于CGPointMake(0,0)
CGPointEqualToPoint(CGPointMake(1,1),CGPointMake(2,2)); // 判断两个点是否相同,布尔型