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

Added view-color indicator to cells within view-hierarchy list. (#239)

Terry Lewis лет назад: 7
Родитель
Сommit
693f57eef7

+ 1 - 0
Classes/Utility/FLEXResources.h

@@ -18,6 +18,7 @@
 + (UIImage *)listIcon;
 + (UIImage *)moveIcon;
 + (UIImage *)selectIcon;
++ (UIImage *)checkerPattern;
 
 + (UIImage *)jsonIcon;
 + (UIImage *)textPlainIcon;

Разница между файлами не показана из-за своего большого размера
+ 27 - 0
Classes/Utility/FLEXResources.m


+ 1 - 0
Classes/ViewHierarchy/FLEXHierarchyTableViewCell.h

@@ -14,5 +14,6 @@
 
 @property (nonatomic, assign) NSInteger viewDepth;
 @property (nonatomic, strong) UIColor *viewColor;
+@property (nonatomic, strong) UIView *viewBackgroundColorView;
 
 @end

+ 23 - 1
Classes/ViewHierarchy/FLEXHierarchyTableViewCell.m

@@ -38,25 +38,37 @@
         self.textLabel.font = [UIFont fontWithName:@"HelveticaNeue-Medium" size:14.0];
         self.detailTextLabel.font = [FLEXUtility defaultTableViewCellLabelFont];
         self.accessoryType = UITableViewCellAccessoryDetailButton;
+        
+        self.viewBackgroundColorView = [[UIView alloc] init];
+        self.viewBackgroundColorView.clipsToBounds = YES;
+        self.viewBackgroundColorView.layer.borderColor = [UIColor blackColor].CGColor;
+        self.viewBackgroundColorView.layer.borderWidth = 1.0f;
+        [self.contentView addSubview:self.viewBackgroundColorView];
     }
     return self;
 }
 
 - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
 {
+    UIColor *originalColour = self.viewBackgroundColorView.backgroundColor;
     [super setHighlighted:highlighted animated:animated];
     
     // UITableViewCell changes all subviews in the contentView to backgroundColor = clearColor.
     // We want to preserve the hierarchy background color when highlighted.
     self.depthIndicatorView.backgroundColor = [FLEXUtility hierarchyIndentPatternColor];
+    
+    self.viewBackgroundColorView.backgroundColor = originalColour;
 }
 
 - (void)setSelected:(BOOL)selected animated:(BOOL)animated
 {
+    UIColor *originalColour = self.viewBackgroundColorView.backgroundColor;
     [super setSelected:selected animated:animated];
     
     // See setHighlighted above.
     self.depthIndicatorView.backgroundColor = [FLEXUtility hierarchyIndentPatternColor];
+    
+    self.viewBackgroundColorView.backgroundColor = originalColour;
 }
 
 - (void)layoutSubviews
@@ -65,6 +77,7 @@
     
     const CGFloat kContentPadding = 10.0;
     const CGFloat kDepthIndicatorWidthMultiplier = 4.0;
+    const CGFloat kViewBackgroundColourDimension = 20;
     
     CGRect depthIndicatorFrame = CGRectMake(kContentPadding, 0, self.viewDepth * kDepthIndicatorWidthMultiplier, self.contentView.bounds.size.height);
     self.depthIndicatorView.frame = depthIndicatorFrame;
@@ -77,7 +90,7 @@
     CGRect textLabelFrame = self.textLabel.frame;
     CGFloat textOriginX = CGRectGetMaxX(circleFrame) + 4.0;
     textLabelFrame.origin.x = textOriginX;
-    textLabelFrame.size.width = CGRectGetMaxX(self.contentView.bounds) - kContentPadding - textOriginX;
+    textLabelFrame.size.width = CGRectGetMaxX(self.contentView.frame) - kContentPadding - textOriginX - kViewBackgroundColourDimension;
     self.textLabel.frame = textLabelFrame;
     
     CGRect detailTextLabelFrame = self.detailTextLabel.frame;
@@ -85,6 +98,15 @@
     detailTextLabelFrame.origin.x = detailOriginX;
     detailTextLabelFrame.size.width = CGRectGetMaxX(self.contentView.bounds) - kContentPadding - detailOriginX;
     self.detailTextLabel.frame = detailTextLabelFrame;
+    
+    CGRect viewBackgroundColourViewFrame = self.textLabel.frame;
+    viewBackgroundColourViewFrame.size.width = kViewBackgroundColourDimension;
+    viewBackgroundColourViewFrame.size.height = kViewBackgroundColourDimension;
+    viewBackgroundColourViewFrame.origin.x = CGRectGetMaxX(self.textLabel.frame) + kContentPadding;
+    viewBackgroundColourViewFrame.origin.y = ABS(CGRectGetHeight(self.contentView.frame) -  CGRectGetHeight(viewBackgroundColourViewFrame)) / 2;
+    
+    self.viewBackgroundColorView.frame = viewBackgroundColourViewFrame;
+    self.viewBackgroundColorView.layer.cornerRadius = kViewBackgroundColourDimension / 2;
 }
 
 - (void)setViewColor:(UIColor *)viewColor

+ 15 - 0
Classes/ViewHierarchy/FLEXHierarchyTableViewController.m

@@ -11,6 +11,7 @@
 #import "FLEXHierarchyTableViewCell.h"
 #import "FLEXObjectExplorerViewController.h"
 #import "FLEXObjectExplorerFactory.h"
+#import "FLEXResources.h"
 
 static const NSInteger kFLEXHierarchyScopeViewsAtTapIndex = 0;
 static const NSInteger kFLEXHierarchyScopeFullHierarchyIndex = 1;
@@ -180,6 +181,20 @@ static const NSInteger kFLEXHierarchyScopeFullHierarchyIndex = 1;
         cell.detailTextLabel.textColor = [UIColor blackColor];
     }
     
+    // Use a pattern-based colour to simplify application of the checker pattern.
+    static UIColor *checkerPatternColour = nil;
+    static dispatch_once_t once;
+    dispatch_once(&once, ^{
+        checkerPatternColour = [UIColor colorWithPatternImage:[FLEXResources checkerPattern]];
+    });
+    
+    UIColor *viewColour = view.backgroundColor;
+    if (!viewColour || [viewColour isEqual:[UIColor clearColor]]) {
+        cell.viewBackgroundColorView.backgroundColor = checkerPatternColour;
+    } else {
+        cell.viewBackgroundColorView.backgroundColor = viewColour;
+    }
+    
     return cell;
 }