UIEdgeInsets 内嵌
/*
typedef struct UIEdgeInsets {
CGFloat top, left, bottom, right;
} UIEdgeInsets;
*/
UIEdgeInsets edgInset = UIEdgeInsetsMake(10, 20, 30, 40);
UIEdgeInsets zeroEdgInset = UIEdgeInsetsZero;
CGRect insetRect = UIEdgeInsetsInsetRect(rect, edgInset);
BOOL isequalEdg = UIEdgeInsetsEqualToEdgeInsets(edgInset, edgInset);
UIOffset 偏移
/*
typedef struct UIOffset {
CGFloat horizontal, vertical;
} UIOffset;
*/
UIOffset offset = UIOffsetMake(100, 200);
UIOffset zeroOffset = UIOffsetZero;
BOOL isOffset = UIOffsetEqualToOffset(offset, offset);
Value 转换 (拓展)
- 初始化 各种结构体
CGPoint point = CGPointMake(100, 100);
CGSize size = CGSizeMake(100, 200);
CGRect rect = CGRectMake(100, 100, 100, 100);
CGVector vector = CGVectorMake(10, 20);
CGAffineTransform transform = CGAffineTransformMake(10, 20, 30, 40, 50, 60);
UIEdgeInsets edgInset = UIEdgeInsetsMake(10, 20, 30, 40);
UIOffset offset = UIOffsetMake(100, 200);
- 转化 NSValue
NSValue *pointValue = [NSValue valueWithCGPoint:point];
NSValue *sizeValue = [NSValue valueWithCGSize:size];
NSValue *rectValue = [NSValue valueWithCGRect:rect];
NSValue *vectorValue = [NSValue valueWithCGVector:vector];
NSValue *transformValue = [NSValue valueWithCGAffineTransform:transform];
NSValue *edgInsetValue = [NSValue valueWithUIEdgeInsets:edgInset];
NSValue *offsetValue = [NSValue valueWithUIOffset:offset];
- 获取
CGPoint point1 = [pointValue CGPointValue];;
CGSize size1 = [sizeValue CGSizeValue];
CGRect rect1 = [rectValue CGRectValue];
CGVector vector1 = [vectorValue CGVectorValue];;
CGAffineTransform transform1 = [transformValue CGAffineTransformValue];
UIEdgeInsets edgInset1 = [edgInsetValue UIEdgeInsetsValue];
UIOffset offset1 = [offsetValue UIOffsetValue];
NSString 互相 转换
- value 转 字符串
NSString *pointString = NSStringFromCGPoint(point);
NSString *sizeString = NSStringFromCGSize(size);
NSString *rectString = NSStringFromCGRect(rect);
NSString *vectorString = NSStringFromCGVector(vector);
NSString *transformString = NSStringFromCGAffineTransform(transform);
NSString *edgInsetString = NSStringFromUIEdgeInsets(edgInset);
NSString *offsetString = NSStringFromUIOffset(offset);
- 字符串 转 value
CGPoint point1 = CGPointFromString(pointString);
CGSize size1 = CGSizeFromString(sizeString);
CGRect rect1 = CGRectFromString(rectString);
CGVector vector1 = CGVectorFromString(vectorString);
CGAffineTransform transform1 = CGAffineTransformFromString(transformString);
UIEdgeInsets edgInset1 = UIEdgeInsetsFromString(edgInsetString);
UIOffset offset1 = UIOffsetFromString(offsetString);
其他
@interface NSCoder (UIGeometryKeyedCoding)
- (void)encodeCGPoint:(CGPoint)point forKey:(NSString *)key;
- (void)encodeCGVector:(CGVector)vector forKey:(NSString *)key;
- (void)encodeCGSize:(CGSize)size forKey:(NSString *)key;
- (void)encodeCGRect:(CGRect)rect forKey:(NSString *)key;
- (void)encodeCGAffineTransform:(CGAffineTransform)transform forKey:(NSString *)key;
- (void)encodeUIEdgeInsets:(UIEdgeInsets)insets forKey:(NSString *)key;
- (void)encodeUIOffset:(UIOffset)offset forKey:(NSString *)key NS_AVAILABLE_IOS(5_0);
- (CGPoint)decodeCGPointForKey:(NSString *)key;
- (CGVector)decodeCGVectorForKey:(NSString *)key;
- (CGSize)decodeCGSizeForKey:(NSString *)key;
- (CGRect)decodeCGRectForKey:(NSString *)key;
- (CGAffineTransform)decodeCGAffineTransformForKey:(NSString *)key;
- (UIEdgeInsets)decodeUIEdgeInsetsForKey:(NSString *)key;
- (UIOffset)decodeUIOffsetForKey:(NSString *)key NS_AVAILABLE_IOS(5_0);
@end
1
网友评论