//自己根据老师的视频讲的敲出来的,有什么有遗漏或有错误的地方希望各位大牛,小牛指教 #import <Foundation/Foundation.h> #import <CoreGraphics/CoreGraphics.h> int main(int argc, const char * argv[]) {
NSString *str1 = @"i am a goodman"; // NSRange r1 = NSMakeRange(2, 4); // NSRange(location,length) //计算“good”在字符串中的位置和长度 NSRange r1 = [str1 rangeOfString:@"good"]; //打印出“good”的位置和长度 NSLog(@"%ld,%ld",r1.location,r1.length);
// NSPoint/CGPoint(CGFloat x, CGFloat y) //定义结构体坐标的方法 NSPoint p1 = NSMakePoint(11, 22); NSPoint p2 = CGPointMake(11, 23); CGPoint p3 = NSMakePoint(12, 12); CGPoint p4 = CGPointMake(123, 44); // CGPointZero = CGPointMake(0, 0);
// NSSize/CGSize(width,height)
NSSize s1 = NSMakeSize(28, 56); NSSize s2 = CGSizeMake(87, 23); CGSize s3 = CGSizeMake(213, 222); CGSize s4 = CGSizeMake(232, 112); // CGSizeZero = CGSizeMake(0, 0);
// NSRect/CGRect(CGPoint/NSPoint,CGSize/NSSize) CGRect c1 = CGRectMake(10, 22, 33, 433); NSRect c2 = {{28,11},{233,111}}; CGRect c3 = {p1,s1};
// 将结构体转化为字符串 NSString *str2 = NSStringFromPoint(p2); NSString *str3 = NSStringFromRect(c3); NSString *str4 = NSStringFromSize(s2); NSString *str5 = NSStringFromRange(r1); NSLog(@"%@,%@,%@,%@",str2,str3,str4,str5);
// 结构体常用函数,返回类型BOOL; int ss = CGPointEqualToPoint(p2,p4); int aa = CGSizeEqualToSize(s3, s4); int dd = CGRectEqualToRect(c2, c3);
// 判断点是否被包含在前面的这个块中 int zz = CGRectContainsPoint(CGRectMake(22, 33, 123, 222), CGPointMake(77, 232));
NSLog(@"%d,%d,%d,%d",ss,aa,dd,zz); return 0; }
|