一、NSRange
NSRange的定義:
typedef struct _NSRange { NSUInteger location; NSUInteger length; } NSRange;NSRanage的使用:
NSRange range = NSMakeRange(8, 10); NSLog(@"location:%zi", range.location); NSLog(@"length:%zi", range.length); NSString *str = NSStringFromRange(range); NSLog(@"%@", str);二、NSPoint
NSPoint的定義:
typedef CGPoint NSPoint;
struct CGPoint { CGFloat x; CGFloat y; }; typedef struct CGPoint CGPoint;NSPoint的使用:
NSPoint p; p.x = 10; p.y = 10; p = NSMakePoint(11, 11); //常見的方式 p = CGPointMake(12, 12); NSString * str = NSStringFromPoint(p); NSLog(@"%@", str);三、NSSize
NSSize的定義:
typedef CGSize NSSize;
struct CGSize { CGFloat width; CGFloat height; }; typedef struct CGSize CGSize;NSSize的使用:
NSSize s; s.width = 100.1; s.height = 100.3; s = NSMakeSize(12.3, 16.9); s = CGSizeMake(15.3, 19.2); NSString *str = NSStringFromSize(s); NSLog(@"%@", str);四、NSRect
NSRect的定義:
typedef CGRect NSRect;
struct CGRect { CGPoint origin; CGSize size; }; typedef struct CGRect CGRect;NSRect的使用:
NSRect r; //r.origin.x = 11; //r.origin.y = 13; r.origin = NSMakePoint(50, 50); r.size = NSMakeSize(60, 60); r = NSMakeRect(20, 20, 30, 30);