标签:style blog color java os 使用 io div log
NSRange(location length)
NSPoint\CGPoint
NSSize\CGSize
NSRect\CGRect (CGPint CGSize)
1、NSRange(location length)
1 void range() 2 { 3 // @"i love oc" // love的范围 4 5 //NSRange r1 = {2, 4}; // 不用 6 //NSRange r2 = {.location = 2, .length = 4};// 不用 7 //NSRange r3 = NSMakeRange(2, 4); // 掌握 8 NSString *str = @"i love oc"; 9 10 // 查找某个字符串在str中的范围 11 // 如果找不到,length=0,location=NSNotFound==-1 12 NSRange range = [str rangeOfString:@"java"]; 13 NSLog(@"loc = %ld, length=%ld", range.location, range.length); 14 }
2、NSPoint\CGPoint
NSSize\CGSize
NSRect\CGRect (CGPint CGSize)
1 void point() 2 { 3 CGPoint p1 = NSMakePoint(10, 10); 4 NSPoint p2 = CGPointMake(20, 20);// 最常用 5 6 NSSize s1 = CGSizeMake(100, 50); 7 NSSize s2 = NSMakeSize(100, 50); 8 CGSize s3 = NSMakeSize(200, 60); 9 10 CGRect r1 = CGRectMake(0, 0, 100, 50); 11 12 CGRect r2 = { {0, 0}, {100, 90}}; 13 14 CGRect r3 = {p1, s2}; 15 16 // 使用CGPointZero等的前提是添加CoreGraphics框架 17 CGRect r4 = {CGPointZero, CGSizeMake(100, 90)}; 18 19 20 // CGSizeZero 21 // CGRectZero 22 23 // 表示原点 24 // CGPointZero == CGPointMake(0, 0) 25 26 27 // 将结构体转为字符串 28 //NSString *str = NSStringFromPoint(p1); 29 30 //NSString *str = NSStringFromSize(s3); 31 32 NSString *str = NSStringFromRect(r1); 33 34 NSLog(@"%@", str); 35 36 37 // NSLog(@"x=%f, y=%f, width=%f, height=%f", r1.origin.x, r1.origin.y, r1.size.width, r1.size.height); 38 } 39 40 //CGRect myRect(CGFloat x, CGFloat y, CGFloat width, CGFloat height) 41 //{ 42 // CGRect rect; 43 // rect.origin.x = x; 44 // rect.origin.y = y; 45 // rect.size.width = width; 46 // rect.size.height = height; 47 // 48 // return rect; 49 //}
3、函数
1 void point() 2 { 3 // 使用这些CGPointEqualToPoint、CGRectContainsPoint等函数的前提是添加CoreGraphics框架 4 // 5 6 // NextStep Foundation 7 8 9 // 比较两个点是否相同(x、y) 10 BOOL b = CGPointEqualToPoint(CGPointMake(10, 10), CGPointMake(10, 10)); 11 //CGRectEqualToRect(<#CGRect rect1#>, <#CGRect rect2#>) 12 //CGSizeEqualToSize(<#CGSize size1#>, <#CGSize size2#>) 13 14 15 // x (50, 150) y (40 , 90) 16 BOOL b2 = CGRectContainsPoint(CGRectMake(50, 40, 100, 50), CGPointMake(60, 45)); 17 18 NSLog(@"%d", b2); 19 20 return 0; 21 }
【黑马程序员】————Foundation框架01常用结构体
标签:style blog color java os 使用 io div log
原文地址:http://www.cnblogs.com/Jr-711/p/3932534.html