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

Show RGB / HLS / A when exploring a color

Tanner Bennett лет назад: 7
Родитель
Сommit
4262074948

+ 25 - 7
Classes/ObjectExplorers/Controllers/FLEXColorExplorerViewController.m

@@ -9,14 +9,24 @@
 #import "FLEXColorExplorerViewController.h"
 
 @interface FLEXColorExplorerViewController ()
-
+@property (nonatomic, readonly) UIColor *colorObject;
 @end
 
 @implementation FLEXColorExplorerViewController
 
-- (BOOL)shouldShowDescription
+- (UIColor *)colorObject
 {
-    return NO;
+    return (UIColor *)self.object;
+}
+
+- (NSString *)displayedObjectDescription
+{
+    CGFloat h, s, l;
+    CGFloat r, g, b, a;
+    [self.colorObject getRed:&r green:&g blue:&b alpha:&a];
+    [self.colorObject getHue:&h saturation:&s brightness:&l alpha:nil];
+    
+    return [NSString stringWithFormat:@"HSL: (%.3f, %.3f, %.3f)\nRGB: (%.3f, %.3f, %.3f)\nAlpha: %.3f", h, s, l, r, g, b, a];
 }
 
 - (NSString *)customSectionTitle
@@ -31,10 +41,18 @@
 
 - (UIView *)customViewForRowCookie:(id)rowCookie
 {
-    CGFloat width = [UIScreen mainScreen].bounds.size.width;
-    UIView *square = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 44)];
-    square.backgroundColor = (UIColor *)self.object;
-    return square;
+    if ([rowCookie isKindOfClass:[NSNumber class]]) {
+        CGFloat width = [UIScreen mainScreen].bounds.size.width;
+        switch ([rowCookie integerValue]) {
+            case 0: {
+                UIView *square = [[UIView alloc] initWithFrame:CGRectMake(0, 0, width, 44)];
+                square.backgroundColor = (UIColor *)self.object;
+                return square;
+            }
+        }
+    }
+    
+    return [super customViewForRowCookie:rowCookie];
 }
 
 - (BOOL)customSectionCanDrillIntoRowWithCookie:(id)rowCookie

+ 3 - 0
Classes/ObjectExplorers/Controllers/FLEXObjectExplorerViewController.h

@@ -49,6 +49,9 @@ typedef NS_ENUM(NSUInteger, FLEXObjectExplorerSection) {
 /// Subclasses can reorder/change which sections can display directly by overriding this method.
 - (NSArray *)possibleExplorerSections;
 
+/// Subclasses can override to provide a more useful description
+- (NSString *)displayedObjectDescription;
+
 @end
 
 @interface FLEXObjectExplorerViewController (Shortcuts)