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

Disable mutli-line rows pre iOS 11

iOS 11 is the first version to support UITableViewAutomaticDimension for default UITableViewCells and their default labels. A future release will backport multiline support to iOS 9-10.

Also cleans up +[FLEXMultilineTableViewCell preferredHeightWithAttributedText:…] and formats it's usages
Tanner Bennett лет назад: 6
Родитель
Сommit
b5a95bacba

+ 6 - 1
Classes/Network/FLEXNetworkTransactionDetailTableViewController.m

@@ -182,7 +182,12 @@ typedef UIViewController *(^FLEXNetworkDetailRowSelectionFuture)(void);
     FLEXNetworkDetailRow *row = [self rowModelAtIndexPath:indexPath];
     NSAttributedString *attributedText = [[self class] attributedTextForRow:row];
     BOOL showsAccessory = row.selectionFuture != nil;
-    return [FLEXMultilineTableViewCell preferredHeightWithAttributedText:attributedText inTableViewWidth:self.tableView.bounds.size.width style:UITableViewStyleGrouped showsAccessory:showsAccessory];
+    return [FLEXMultilineTableViewCell
+        preferredHeightWithAttributedText:attributedText
+        maxWidth:tableView.bounds.size.width
+        style:tableView.style
+        showsAccessory:showsAccessory
+    ];
 }
 
 - (FLEXNetworkDetailRow *)rowModelAtIndexPath:(NSIndexPath *)indexPath

+ 13 - 4
Classes/ObjectExplorers/FLEXObjectExplorerViewController.m

@@ -335,13 +335,22 @@
 
 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
 {
-    // For the description section, we want that nice slim looking row.
+    // For the description section, we want that nice slim/snug looking row.
     // Other rows use the automatic size.
     FLEXExplorerSection *section = self.sections[indexPath.section];
+    
     if (section == self.descriptionSection) {
-        NSString *text = self.explorer.objectDescription;
-        NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:@{ NSFontAttributeName : UIFont.flex_defaultTableCellFont }];
-        return [FLEXMultilineTableViewCell preferredHeightWithAttributedText:attributedText inTableViewWidth:self.tableView.frame.size.width style:tableView.style showsAccessory:NO];
+        NSAttributedString *attributedText = [[NSAttributedString alloc]
+            initWithString:self.explorer.objectDescription
+            attributes:@{ NSFontAttributeName : UIFont.flex_defaultTableCellFont }
+        ];
+        
+        return [FLEXMultilineTableViewCell
+            preferredHeightWithAttributedText:attributedText
+            maxWidth:tableView.frame.size.width
+            style:tableView.style
+            showsAccessory:NO
+        ];
     }
 
     return UITableViewAutomaticDimension;

+ 6 - 1
Classes/ObjectExplorers/Sections/Shortcuts/FLEXShortcutsSection.m

@@ -205,7 +205,12 @@
 }
 
 - (NSString *)reuseIdentifierForRow:(NSInteger)row {
-    return [self.shortcuts[row] customReuseIdentifierWith:self.object] ?: kFLEXMultilineDetailCell;
+    FLEXTableViewCellReuseIdentifier defaultReuse = kFLEXDetailCell;
+    if (@available(iOS 11, *)) {
+        defaultReuse = kFLEXMultilineDetailCell;
+    }
+    
+    return [self.shortcuts[row] customReuseIdentifierWith:self.object] ?: defaultReuse;
 }
 
 - (void)configureCell:(__kindof FLEXTableViewCell *)cell forRow:(NSInteger)row {

+ 8 - 1
Classes/ObjectExplorers/Views/FLEXCodeFontCell.m

@@ -21,7 +21,14 @@
     self.titleLabel.minimumScaleFactor = 0.9;
     self.subtitleLabel.adjustsFontSizeToFitWidth = YES;
     self.subtitleLabel.minimumScaleFactor = 0.75;
-    self.subtitleLabel.numberOfLines = 5;
+    
+    // Disable mutli-line pre iOS 11
+    if (@available(iOS 11, *)) {
+        self.subtitleLabel.numberOfLines = 5;
+    } else {
+        self.titleLabel.numberOfLines = 1;
+        self.subtitleLabel.numberOfLines = 1;
+    }
 }
 
 @end

+ 4 - 1
Classes/ObjectExplorers/Views/FLEXMultilineTableViewCell.h

@@ -11,7 +11,10 @@
 /// A cell with both labels set to be multi-line capable.
 @interface FLEXMultilineTableViewCell : FLEXTableViewCell
 
-+ (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText inTableViewWidth:(CGFloat)tableViewWidth style:(UITableViewStyle)style showsAccessory:(BOOL)showsAccessory;
++ (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText
+                                    maxWidth:(CGFloat)contentViewWidth
+                                       style:(UITableViewStyle)style
+                              showsAccessory:(BOOL)showsAccessory;
 
 @end
 

+ 9 - 3
Classes/ObjectExplorers/Views/FLEXMultilineTableViewCell.m

@@ -8,6 +8,7 @@
 
 #import "FLEXMultilineTableViewCell.h"
 #import "UIView+FLEX_Layout.h"
+#import "FLEXUtility.h"
 
 @interface FLEXMultilineTableViewCell ()
 @property (nonatomic, readonly) UILabel *_titleLabel;
@@ -29,10 +30,10 @@
 }
 
 + (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText
-                            inTableViewWidth:(CGFloat)tableViewWidth
+                                    maxWidth:(CGFloat)contentViewWidth
                                        style:(UITableViewStyle)style
                               showsAccessory:(BOOL)showsAccessory {
-    CGFloat labelWidth = tableViewWidth;
+    CGFloat labelWidth = contentViewWidth;
 
     // Content view inset due to accessory view observed on iOS 8.1 iPhone 6.
     if (showsAccessory) {
@@ -43,7 +44,12 @@
     labelWidth -= (labelInsets.left + labelInsets.right);
 
     CGSize constrainSize = CGSizeMake(labelWidth, CGFLOAT_MAX);
-    CGFloat preferredLabelHeight = ceil([attributedText boundingRectWithSize:constrainSize options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.height);
+    CGRect boundingBox = [attributedText
+        boundingRectWithSize:constrainSize
+        options:NSStringDrawingUsesLineFragmentOrigin
+        context:nil
+    ];
+    CGFloat preferredLabelHeight = FLEXFloor(boundingBox.size.height);
     CGFloat preferredCellHeight = preferredLabelHeight + labelInsets.top + labelInsets.bottom + 1.0;
 
     return preferredCellHeight;

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

@@ -42,6 +42,9 @@
     
     self.titleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
     self.subtitleLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
+    
+    self.titleLabel.numberOfLines = 1;
+    self.subtitleLabel.numberOfLines = 1;
 }
 
 - (UILabel *)titleLabel {