Просмотр исходного кода

Add method to get a more readable string for a CGRect.

NSStringFromCGRect() doesn’t quite cut it.
Ryan Olson лет назад: 12
Родитель
Сommit
4050e7a49e
2 измененных файлов с 8 добавлено и 2 удалено
  1. 1 0
      Classes/Utility/FLEXUtility.h
  2. 7 2
      Classes/Utility/FLEXUtility.m

+ 1 - 0
Classes/Utility/FLEXUtility.h

@@ -13,6 +13,7 @@
 
 
 + (UIColor *)consistentRandomColorForObject:(id)object;
 + (UIColor *)consistentRandomColorForObject:(id)object;
 + (NSString *)descriptionForView:(UIView *)view includingFrame:(BOOL)includeFrame;
 + (NSString *)descriptionForView:(UIView *)view includingFrame:(BOOL)includeFrame;
++ (NSString *)stringForCGRect:(CGRect)rect;
 + (UIViewController *)viewControllerForView:(UIView *)view;
 + (UIViewController *)viewControllerForView:(UIView *)view;
 + (NSString *)detailDescriptionForView:(UIView *)view;
 + (NSString *)detailDescriptionForView:(UIView *)view;
 + (UIImage *)circularImageWithColor:(UIColor *)color radius:(CGFloat)radius;
 + (UIImage *)circularImageWithColor:(UIColor *)color radius:(CGFloat)radius;

+ 7 - 2
Classes/Utility/FLEXUtility.m

@@ -27,7 +27,7 @@
     }
     }
     
     
     if (includeFrame) {
     if (includeFrame) {
-        description = [description stringByAppendingFormat:@" frame:%@", NSStringFromCGRect(view.frame)];
+        description = [description stringByAppendingFormat:@" frame %@", [self stringForCGRect:view.frame]];
     }
     }
     
     
     if ([view.accessibilityLabel length] > 0) {
     if ([view.accessibilityLabel length] > 0) {
@@ -37,6 +37,11 @@
     return description;
     return description;
 }
 }
 
 
++ (NSString *)stringForCGRect:(CGRect)rect
+{
+    return [NSString stringWithFormat:@"{x: %g, y: %g, w: %g, h: %g}", rect.origin.x, rect.origin.y, rect.size.width, rect.size.height];
+}
+
 + (UIViewController *)viewControllerForView:(UIView *)view
 + (UIViewController *)viewControllerForView:(UIView *)view
 {
 {
     UIViewController *viewController = nil;
     UIViewController *viewController = nil;
@@ -52,7 +57,7 @@
 
 
 + (NSString *)detailDescriptionForView:(UIView *)view
 + (NSString *)detailDescriptionForView:(UIView *)view
 {
 {
-    return [NSString stringWithFormat:@"frame = %@", NSStringFromCGRect(view.frame)];
+    return [NSString stringWithFormat:@"frame %@", [self stringForCGRect:view.frame]];
 }
 }
 
 
 + (UIImage *)circularImageWithColor:(UIColor *)color radius:(CGFloat)radius
 + (UIImage *)circularImageWithColor:(UIColor *)color radius:(CGFloat)radius