Explorar o código

Refactor FLEXTableViewCell

Tanner Bennett %!s(int64=6) %!d(string=hai) anos
pai
achega
965419bd58

+ 18 - 17
Classes/ObjectExplorers/Views/FLEXMultilineTableViewCell.m

@@ -7,33 +7,34 @@
 //
 //
 
 
 #import "FLEXMultilineTableViewCell.h"
 #import "FLEXMultilineTableViewCell.h"
+#import "UIView+FLEX_Layout.h"
+
+@interface FLEXMultilineTableViewCell ()
+@property (nonatomic, readonly) UILabel *_titleLabel;
+@property (nonatomic, readonly) UILabel *_subtitleLabel;
+@property (nonatomic) BOOL constraintsUpdated;
+@end
 
 
 @implementation FLEXMultilineTableViewCell
 @implementation FLEXMultilineTableViewCell
 
 
-- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
-{
+- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     if (self) {
     if (self) {
-        self.textLabel.numberOfLines = 0;
-        self.detailTextLabel.numberOfLines = 0;
+        self.titleLabel.numberOfLines = 0;
+        self.subtitleLabel.numberOfLines = 0;
     }
     }
-    return self;
-}
 
 
-- (void)layoutSubviews
-{
-    [super layoutSubviews];
-
-    self.textLabel.frame = UIEdgeInsetsInsetRect(self.contentView.bounds, [[self class] labelInsets]);
+    return self;
 }
 }
 
 
-+ (UIEdgeInsets)labelInsets
-{
++ (UIEdgeInsets)labelInsets {
     return UIEdgeInsetsMake(10.0, 15.0, 10.0, 15.0);
     return UIEdgeInsetsMake(10.0, 15.0, 10.0, 15.0);
 }
 }
 
 
-+ (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText inTableViewWidth:(CGFloat)tableViewWidth style:(UITableViewStyle)style showsAccessory:(BOOL)showsAccessory
-{
++ (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText
+                            inTableViewWidth:(CGFloat)tableViewWidth
+                                       style:(UITableViewStyle)style
+                              showsAccessory:(BOOL)showsAccessory {
     CGFloat labelWidth = tableViewWidth;
     CGFloat labelWidth = tableViewWidth;
 
 
     // Content view inset due to accessory view observed on iOS 8.1 iPhone 6.
     // Content view inset due to accessory view observed on iOS 8.1 iPhone 6.
@@ -53,10 +54,10 @@
 
 
 @end
 @end
 
 
+
 @implementation FLEXMultilineDetailTableViewCell
 @implementation FLEXMultilineDetailTableViewCell
 
 
-- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
-{
+- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
     return [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
     return [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
 }
 }
 
 

+ 2 - 2
Classes/ObjectExplorers/Views/FLEXSubtitleTableViewCell.h

@@ -6,9 +6,9 @@
 //  Copyright © 2019 Flipboard. All rights reserved.
 //  Copyright © 2019 Flipboard. All rights reserved.
 //
 //
 
 
-#import <UIKit/UIKit.h>
+#import "FLEXTableViewCell.h"
 
 
 /// A cell initialized with \c UITableViewCellStyleSubtitle
 /// A cell initialized with \c UITableViewCellStyleSubtitle
-@interface FLEXSubtitleTableViewCell : UITableViewCell
+@interface FLEXSubtitleTableViewCell : FLEXTableViewCell
 
 
 @end
 @end

+ 5 - 0
Classes/ObjectExplorers/Views/FLEXTableViewCell.h

@@ -10,4 +10,9 @@
 
 
 @interface FLEXTableViewCell : UITableViewCell
 @interface FLEXTableViewCell : UITableViewCell
 
 
+/// Use this instead of .textLabel
+@property (nonatomic, readonly) UILabel *titleLabel;
+/// Use this instead of .detailTextLabel
+@property (nonatomic, readonly) UILabel *subtitleLabel;
+
 @end
 @end

+ 15 - 3
Classes/ObjectExplorers/Views/FLEXTableViewCell.m

@@ -8,6 +8,7 @@
 
 
 #import "FLEXTableViewCell.h"
 #import "FLEXTableViewCell.h"
 #import "FLEXUtility.h"
 #import "FLEXUtility.h"
+#import "FLEXColor.h"
 #import "FLEXTableView.h"
 #import "FLEXTableView.h"
 
 
 @interface UITableView (Internal)
 @interface UITableView (Internal)
@@ -28,14 +29,25 @@
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     if (self) {
     if (self) {
         UIFont *cellFont = [FLEXUtility defaultTableViewCellLabelFont];
         UIFont *cellFont = [FLEXUtility defaultTableViewCellLabelFont];
-        self.textLabel.font = cellFont;
-        self.detailTextLabel.font = cellFont;
-        self.detailTextLabel.textColor = UIColor.grayColor;
+        self.titleLabel.font = cellFont;
+        self.subtitleLabel.font = cellFont;
+        self.subtitleLabel.textColor = [FLEXColor deemphasizedTextColor];
+        
+        self.titleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
+        self.subtitleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
     }
     }
 
 
     return self;
     return self;
 }
 }
 
 
+- (UILabel *)titleLabel {
+    return self.textLabel;
+}
+
+- (UILabel *)subtitleLabel {
+    return self.detailTextLabel;
+}
+
 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
 - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
 {
 {
     return [self._tableView _canPerformAction:action forCell:self sender:sender];
     return [self._tableView _canPerformAction:action forCell:self sender:sender];