码迷,mamicode.com
首页 > 其他好文 > 详细

关于OC中直接打印结构体,点(CGRect,CGSize,CGPoint,UIOffset)等数据类型

时间:2016-04-13 23:57:45      阅读:912      评论:0      收藏:0      [点我收藏+]

标签:

关于OC直接打印结构体,点(CGRect,CGSize,CGPoint,UIOffset)等数据类型,我们完全可以把其转换为OC对象来进项打印调试,而不必对结构体中的成员变量进行打印.就好比我们可以使用NSStringFromCGRect(CGRect rect)来直接打印一个结构体,其他打印可以参考以下内容

UIKIT_EXTERN NSString *NSStringFromCGPoint(CGPoint point);

UIKIT_EXTERN NSString *NSStringFromCGVector(CGVector vector);

UIKIT_EXTERN NSString *NSStringFromCGSize(CGSize size);

UIKIT_EXTERN NSString *NSStringFromCGRect(CGRect rect);

UIKIT_EXTERN NSString *NSStringFromCGAffineTransform(CGAffineTransform transform);

UIKIT_EXTERN NSString *NSStringFromUIEdgeInsets(UIEdgeInsets insets);

UIKIT_EXTERN NSString *NSStringFromUIOffset(UIOffset offset);

OC中好多几何学中的内容,一般都包括在 UIGeometry.h 文件中 仔细看看,可以学到好多东西

 

  1  NS_ASSUME_NONNULL_BEGIN
  2 
  3 typedef struct UIEdgeInsets {
  4     CGFloat top, left, bottom, right;  // specify amount to inset (positive) for each of the edges. values can be negative to ‘outset‘
  5 } UIEdgeInsets;
  6 
  7 typedef struct UIOffset {
  8     CGFloat horizontal, vertical; // specify amount to offset a position, positive for right or down, negative for left or up
  9 } UIOffset;
 10 
 11 typedef NS_OPTIONS(NSUInteger, UIRectEdge) {
 12     UIRectEdgeNone   = 0,
 13     UIRectEdgeTop    = 1 << 0,
 14     UIRectEdgeLeft   = 1 << 1,
 15     UIRectEdgeBottom = 1 << 2,
 16     UIRectEdgeRight  = 1 << 3,
 17     UIRectEdgeAll    = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight
 18 } NS_ENUM_AVAILABLE_IOS(7_0);
 19 
 20 UIKIT_STATIC_INLINE UIEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) {
 21     UIEdgeInsets insets = {top, left, bottom, right};
 22     return insets;
 23 }
 24 
 25 UIKIT_STATIC_INLINE CGRect UIEdgeInsetsInsetRect(CGRect rect, UIEdgeInsets insets) {
 26     rect.origin.x    += insets.left;
 27     rect.origin.y    += insets.top;
 28     rect.size.width  -= (insets.left + insets.right);
 29     rect.size.height -= (insets.top  + insets.bottom);
 30     return rect;
 31 }
 32 
 33 UIKIT_STATIC_INLINE UIOffset UIOffsetMake(CGFloat horizontal, CGFloat vertical) {
 34     UIOffset offset = {horizontal, vertical};
 35     return offset;
 36 }
 37 
 38 UIKIT_STATIC_INLINE BOOL UIEdgeInsetsEqualToEdgeInsets(UIEdgeInsets insets1, UIEdgeInsets insets2) {
 39     return insets1.left == insets2.left && insets1.top == insets2.top && insets1.right == insets2.right && insets1.bottom == insets2.bottom;
 40 }
 41 
 42 UIKIT_STATIC_INLINE BOOL UIOffsetEqualToOffset(UIOffset offset1, UIOffset offset2) {
 43     return offset1.horizontal == offset2.horizontal && offset1.vertical == offset2.vertical;
 44 }
 45 
 46 UIKIT_EXTERN const UIEdgeInsets UIEdgeInsetsZero;
 47 UIKIT_EXTERN const UIOffset UIOffsetZero;
 48 
 49 // 结构体等数据类型 --> OC对象
 50 UIKIT_EXTERN NSString *NSStringFromCGPoint(CGPoint point);
 51 UIKIT_EXTERN NSString *NSStringFromCGVector(CGVector vector);
 52 UIKIT_EXTERN NSString *NSStringFromCGSize(CGSize size);
 53 UIKIT_EXTERN NSString *NSStringFromCGRect(CGRect rect);
 54 UIKIT_EXTERN NSString *NSStringFromCGAffineTransform(CGAffineTransform transform);
 55 UIKIT_EXTERN NSString *NSStringFromUIEdgeInsets(UIEdgeInsets insets);
 56 UIKIT_EXTERN NSString *NSStringFromUIOffset(UIOffset offset);
 57 
 58 // OC对象 --> 结构体等数据类型
 59 UIKIT_EXTERN CGPoint CGPointFromString(NSString *string);
 60 UIKIT_EXTERN CGVector CGVectorFromString(NSString *string);
 61 UIKIT_EXTERN CGSize CGSizeFromString(NSString *string);
 62 UIKIT_EXTERN CGRect CGRectFromString(NSString *string);
 63 UIKIT_EXTERN CGAffineTransform CGAffineTransformFromString(NSString *string);
 64 UIKIT_EXTERN UIEdgeInsets UIEdgeInsetsFromString(NSString *string);
 65 UIKIT_EXTERN UIOffset UIOffsetFromString(NSString *string);
 66 
 67 @interface NSValue (NSValueUIGeometryExtensions)
 68 
 69 + (NSValue *)valueWithCGPoint:(CGPoint)point;
 70 + (NSValue *)valueWithCGVector:(CGVector)vector;
 71 + (NSValue *)valueWithCGSize:(CGSize)size;
 72 + (NSValue *)valueWithCGRect:(CGRect)rect;
 73 + (NSValue *)valueWithCGAffineTransform:(CGAffineTransform)transform;
 74 + (NSValue *)valueWithUIEdgeInsets:(UIEdgeInsets)insets;
 75 + (NSValue *)valueWithUIOffset:(UIOffset)insets NS_AVAILABLE_IOS(5_0);
 76 
 77 - (CGPoint)CGPointValue;
 78 - (CGVector)CGVectorValue;
 79 - (CGSize)CGSizeValue;
 80 - (CGRect)CGRectValue;
 81 - (CGAffineTransform)CGAffineTransformValue;
 82 - (UIEdgeInsets)UIEdgeInsetsValue;
 83 - (UIOffset)UIOffsetValue NS_AVAILABLE_IOS(5_0);
 84 
 85 @end
 86 
 87 @interface NSCoder (UIGeometryKeyedCoding)
 88 
 89 - (void)encodeCGPoint:(CGPoint)point forKey:(NSString *)key;
 90 - (void)encodeCGVector:(CGVector)vector forKey:(NSString *)key;
 91 - (void)encodeCGSize:(CGSize)size forKey:(NSString *)key;
 92 - (void)encodeCGRect:(CGRect)rect forKey:(NSString *)key;
 93 - (void)encodeCGAffineTransform:(CGAffineTransform)transform forKey:(NSString *)key;
 94 - (void)encodeUIEdgeInsets:(UIEdgeInsets)insets forKey:(NSString *)key;
 95 - (void)encodeUIOffset:(UIOffset)offset forKey:(NSString *)key NS_AVAILABLE_IOS(5_0);
 96 
 97 - (CGPoint)decodeCGPointForKey:(NSString *)key;
 98 - (CGVector)decodeCGVectorForKey:(NSString *)key;
 99 - (CGSize)decodeCGSizeForKey:(NSString *)key;
100 - (CGRect)decodeCGRectForKey:(NSString *)key;
101 - (CGAffineTransform)decodeCGAffineTransformForKey:(NSString *)key;
102 - (UIEdgeInsets)decodeUIEdgeInsetsForKey:(NSString *)key;
103 - (UIOffset)decodeUIOffsetForKey:(NSString *)key NS_AVAILABLE_IOS(5_0);
104 
105 @end
106 
107 NS_ASSUME_NONNULL_END

 

 

 

关于OC中直接打印结构体,点(CGRect,CGSize,CGPoint,UIOffset)等数据类型

标签:

原文地址:http://www.cnblogs.com/chao8888/p/5389297.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!