Code:
#import <Foundation/Foundation.h>
#import "stdbool.h"
int main(int argc, char* argv[]) {
@autoreleasepool {
// NSRange
NSRange range = NSMakeRange(0, 5);
NSLog(@"NSRange range = %@", NSStringFromRange(range));
// NSPoint/CGPoint
NSPoint point1 = NSMakePoint(0, 0);
CGPoint point2 = CGPointMake(100, 100);
NSLog(@"NSPoint point1 = %@", NSStringFromPoint(point1));
NSLog(@"CGPoint point2 = %@", NSStringFromPoint(point2));
// NSSize/CGSize
NSSize size1 = NSMakeSize(40, 60);
CGSize size2 = CGSizeMake(70, 30);
NSLog(@"NSSize size1 = %@", NSStringFromSize(size1));
NSLog(@"CGSize size2 = %@", NSStringFromSize(size2));
// NSRect/CGRect
NSRect rect1 = NSMakeRect(0, 0, 800, 600);
CGRect rect2 = CGRectMake(0, 0, 800, 600);
NSLog(@"NSRect rect1 = %@", NSStringFromRect(rect1));
NSLog(@"CGRect rect2 = %@", NSStringFromRect(rect2));
// CGPointZero == CGPointMake(0, 0)
CGRect rect3 = {{0, 0}, {800, 600}};
NSLog(@"CGRect rect3 = %@", NSStringFromRect(rect3));
CGRect rect4 = { CGPointZero, CGSizeMake(800, 600)};
NSLog(@"CGRect rect4 = %@", NSStringFromRect(rect4));
// 与CGPointZero类似,还有CGSizeZero、CGRectZero
// CGSizeZero == CGSizeMake(0, 0)
// CGRectZero == CGRectMake(0, 0, 0, 0)
bool isSamePoint = CGPointEqualToPoint(CGPointMake(100,100), CGPointMake(100,100));
NSLog(@"%@", isSamePoint ? @"Two points are same." : @"Two points are not same.");
bool isContain = CGRectContainsPoint(CGRectMake(100, 100, 200, 200), CGPointMake(150, 150));
NSLog(@"%@", isContain ? @"The rectangle contains the point." : @"The rectangle does not contain the point.");
}
return 0;
}
Output:
NSRange range = {0, 5}
NSPoint point1 = {0, 0}
CGPoint point2 = {100, 100}
NSSize size1 = {40, 60}
CGSize size2 = {70, 30}
NSRect rect1 = {{0, 0}, {800, 600}}
CGRect rect2 = {{0, 0}, {800, 600}}
CGRect rect3 = {{0, 0}, {800, 600}}
CGRect rect4 = {{0, 0}, {800, 600}}
Two points are same.
The rectangle contains the point.