结构体: NSRange(location length) NSRange r1 = {2, 4};//不用 NSRange r2 = {.location = 2, .length = 4};//不用 NSRange r3 = NSMakeRange(2, 4); //表示一个点 NSPoint\CGPoint // CGPointMake(CGFloat x, CGFloat y) struct CGPoint { CGFloat x; CGFloat y; };
//表示平面的面积 NSSize\CGSize //CGSizeMake(CGFloat width, CGFloat height) struct CGSize { CGFloat width; CGFloat height;
//表示平面左上角是某个点的矩形区域 NSRect\CGRect(CGPoint CGSize) //CGRectMake(CGFloat x, CGFloat y, CGFloat width, CGFloat height) struct CGRect { CGPoint origin; CGSize size;
};
#import <Foundation/Foundation.h>
int main() { NSRange r1 = {2, 4};//不用 NSRange r2 = {.location = 2, .length = 4};//不用 NSRange r3 = NSMakeRange(2, 4);
NSString *str = @“i love oc”;
//查找某个字符串在str中的范围 //如果找不到,length = 0,location = NSNotFound==-1 NSRange range = [str rangeOfString:@“ve o”];
NSLog(@“location = %ld, length = %ld”, range.location, range.length);
//使用这些函数的前提是添加coreGraphics框架 //创建点 CGPoint P1 = NSMakePoint(10, 10); NSPoint p2 = CGPointMake(20, 20);//最常用 //创建矩形大小 CGSize s1 = CGSizeMake(100, 50);//最常用 NSSize s2 = NSMakeSize(100, 50); //创建矩形 CGRect r1 = CGRectMake(0, 0, 100, 50);
CGRect r2 = {{0, 0},{100, 90}};
CGRect r3 = {p1, s2};
CGPointMake(0, 0);
//表示原点 //CGPointZero == CGPointMake(0, 0);
//比较两个点是否相同(x,y) CGPointEqualToPoint(CGPointMake(10, 10), CGPointMake(10, 10));
//判断rect中是否包含point CGRectContainsPoint(CGRectMake(50, 40, 100, 50), CGPointMake(130, 70));
//将结构体转成字符串 NSString *str = NSStringFromPoint(P1); NSString *str1 = NSStringFromSize(s1); NSString *str2 = NSStringFromRect(r1);
NSLog(@"p1=%@, s1=%@, r1=%@", str, str1, str2);
//NSLog(@"x=%f, y=%f, width=%f, height=%f",r1.origin.x, r1.origin.y, r1.size.width, r1.size.height );
return 0; } //CGRect myRect (CGFloat x, CGFloat y, CGFloat width, CGFloat height) //{ // CGRect rect; // //访问CGRect内的值 // rect.origin.x = x; // rect.origin.y = y; // rect.size.width = width; // rect.size.height = height; // // return rect; //}
|