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

Replace FLEXDescriptionTableViewCell with a more generic multiline cell class.

Ryan Olson лет назад: 11
Родитель
Сommit
190006dcc0

+ 0 - 15
Classes/Object Explorers/FLEXDescriptionTableViewCell.h

@@ -1,15 +0,0 @@
-//
-//  FLEXDescriptionTableViewCell.h
-//  Flipboard
-//
-//  Created by Ryan Olson on 2014-05-05.
-//  Copyright (c) 2014 Flipboard. All rights reserved.
-//
-
-#import <UIKit/UIKit.h>
-
-@interface FLEXDescriptionTableViewCell : UITableViewCell
-
-+ (CGFloat)preferredHeightWithText:(NSString *)text inTableViewWidth:(CGFloat)tableViewWidth;
-
-@end

+ 6 - 4
Classes/Object Explorers/FLEXObjectExplorerViewController.m

@@ -9,7 +9,7 @@
 #import "FLEXObjectExplorerViewController.h"
 #import "FLEXUtility.h"
 #import "FLEXRuntimeUtility.h"
-#import "FLEXDescriptionTableViewCell.h"
+#import "FLEXMultilineTableViewCell.h"
 #import "FLEXObjectExplorerFactory.h"
 #import "FLEXPropertyEditorViewController.h"
 #import "FLEXIvarEditorViewController.h"
@@ -860,11 +860,12 @@ static const NSInteger kFLEXObjectExplorerScopeIncludeInheritanceIndex = 1;
     FLEXObjectExplorerSection explorerSection = [self explorerSectionAtIndex:indexPath.section];
     
     BOOL useDescriptionCell = explorerSection == FLEXObjectExplorerSectionDescription;
-    NSString *cellIdentifier = useDescriptionCell ? @"descriptionCell" : @"cell";
+    NSString *cellIdentifier = useDescriptionCell ? kFLEXMultilineTableViewCellIdentifier : @"cell";
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
     if (!cell) {
         if (useDescriptionCell) {
-            cell = [[FLEXDescriptionTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
+            cell = [[FLEXMultilineTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
+            cell.textLabel.font = [FLEXUtility defaultTableViewCellLabelFont];
         } else {
             cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
             UIFont *cellFont = [FLEXUtility defaultTableViewCellLabelFont];
@@ -887,7 +888,8 @@ static const NSInteger kFLEXObjectExplorerScopeIncludeInheritanceIndex = 1;
     CGFloat height = self.tableView.rowHeight;
     if (explorerSection == FLEXObjectExplorerSectionDescription) {
         NSString *text = [self titleForRow:indexPath.row inExplorerSection:explorerSection];
-        CGFloat preferredHeight = [FLEXDescriptionTableViewCell preferredHeightWithText:text inTableViewWidth:self.tableView.frame.size.width];
+        NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:@{ NSFontAttributeName : [FLEXUtility defaultTableViewCellLabelFont] }];
+        CGFloat preferredHeight = [FLEXMultilineTableViewCell preferredHeightWithAttributedText:attributedText inTableViewWidth:self.tableView.frame.size.width style:tableView.style showsAccessory:NO];
         height = MAX(height, preferredHeight);
     }
     return height;

+ 17 - 0
Classes/Utility/FLEXMultilineTableViewCell.h

@@ -0,0 +1,17 @@
+//
+//  FLEXMultilineTableViewCell.h
+//  UICatalog
+//
+//  Created by Ryan Olson on 2/13/15.
+//  Copyright (c) 2015 f. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+extern NSString *const kFLEXMultilineTableViewCellIdentifier;
+
+@interface FLEXMultilineTableViewCell : UITableViewCell
+
++ (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText inTableViewWidth:(CGFloat)tableViewWidth style:(UITableViewStyle)style showsAccessory:(BOOL)showsAccessory;
+
+@end

+ 23 - 29
Classes/Object Explorers/FLEXDescriptionTableViewCell.m

@@ -1,26 +1,22 @@
 //
-//  FLEXDescriptionTableViewCell.m
-//  Flipboard
+//  FLEXMultilineTableViewCell.m
+//  UICatalog
 //
-//  Created by Ryan Olson on 2014-05-05.
-//  Copyright (c) 2014 Flipboard. All rights reserved.
+//  Created by Ryan Olson on 2/13/15.
+//  Copyright (c) 2015 f. All rights reserved.
 //
 
-#import "FLEXDescriptionTableViewCell.h"
-#import "FLEXUtility.h"
+#import "FLEXMultilineTableViewCell.h"
 
-@interface FLEXDescriptionTableViewCell ()
+NSString *const kFLEXMultilineTableViewCellIdentifier = @"kFLEXMultilineTableViewCellIdentifier";
 
-@end
-
-@implementation FLEXDescriptionTableViewCell
+@implementation FLEXMultilineTableViewCell
 
-- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
+- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
 {
     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
     if (self) {
         self.textLabel.numberOfLines = 0;
-        self.textLabel.font = [[self class] labelFont];
     }
     return self;
 }
@@ -28,23 +24,18 @@
 - (void)layoutSubviews
 {
     [super layoutSubviews];
-    
-    self.textLabel.frame = UIEdgeInsetsInsetRect(self.contentView.bounds, [[self class] labelInsets]);
-}
 
-+ (UIFont *)labelFont
-{
-    return [FLEXUtility defaultTableViewCellLabelFont];
+    self.textLabel.frame = UIEdgeInsetsInsetRect(self.contentView.bounds, [[self class] labelInsets]);
 }
 
 + (UIEdgeInsets)labelInsets
 {
     UIEdgeInsets labelInsets = UIEdgeInsetsZero;
-    labelInsets.top = 15.0;
-    labelInsets.bottom = 15.0;
+    labelInsets.top = 10.0;
+    labelInsets.bottom = 10.0;
     if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
         labelInsets.left = 15.0;
-        labelInsets.right = 0.0;
+        labelInsets.right = 15.0;
     } else {
         labelInsets.left = 10.0;
         labelInsets.right = 10.0;
@@ -52,7 +43,7 @@
     return labelInsets;
 }
 
-+ (CGFloat)preferredHeightWithText:(NSString *)text inTableViewWidth:(CGFloat)tableViewWidth
++ (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText inTableViewWidth:(CGFloat)tableViewWidth style:(UITableViewStyle)style showsAccessory:(BOOL)showsAccessory
 {
     // Hardcoded margins from observation of cells in a grouped table on iOS 6.
     // There is no API to get the insets of the content view proir to layout.
@@ -60,25 +51,28 @@
     // Differences are between the content view's width and the table view's width
     // Full screen iPhone - 20
     // Full screen iPad - 90
-    
+
     CGFloat labelWidth = tableViewWidth;
-    if (NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_6_1) {
+    if (NSFoundationVersionNumber <= NSFoundationVersionNumber_iOS_6_1 && style == UITableViewStyleGrouped) {
         if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
             labelWidth -= 40.0;
         } else {
             labelWidth -= 90.0;
         }
     }
-    
+
+    // Content view inset due to accessory view observed on iOS 8.1 iPhone 6.
+    if (showsAccessory) {
+        labelWidth -= 34.0;
+    }
+
     UIEdgeInsets labelInsets = [self labelInsets];
     labelWidth -= (labelInsets.left + labelInsets.right);
-    
-    // Size an attributed string to get around deprecation warnings if the deployment target is >= 7 while still supporting deployment tagets back to 6.0.
-    NSAttributedString *attributedText = [[NSAttributedString alloc] initWithString:text attributes:@{NSFontAttributeName: [self labelFont]}];
+
     CGSize constrainSize = CGSizeMake(labelWidth, CGFLOAT_MAX);
     CGFloat preferredLabelHeight = ceil([attributedText boundingRectWithSize:constrainSize options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.height);
     CGFloat preferredCellHeight = preferredLabelHeight + labelInsets.top + labelInsets.bottom + 1.0;
-    
+
     return preferredCellHeight;
 }
 

+ 6 - 6
Example/UICatalog.xcodeproj/project.pbxproj

@@ -49,7 +49,6 @@
 		944F7489197B458C009AB039 /* FLEXArrayExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7426197B458C009AB039 /* FLEXArrayExplorerViewController.m */; };
 		944F748A197B458C009AB039 /* FLEXClassExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7428197B458C009AB039 /* FLEXClassExplorerViewController.m */; };
 		944F748B197B458C009AB039 /* FLEXDefaultsExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F742A197B458C009AB039 /* FLEXDefaultsExplorerViewController.m */; };
-		944F748C197B458C009AB039 /* FLEXDescriptionTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F742C197B458C009AB039 /* FLEXDescriptionTableViewCell.m */; };
 		944F748D197B458C009AB039 /* FLEXDictionaryExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F742E197B458C009AB039 /* FLEXDictionaryExplorerViewController.m */; };
 		944F748E197B458C009AB039 /* FLEXImageExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7430197B458C009AB039 /* FLEXImageExplorerViewController.m */; };
 		944F748F197B458C009AB039 /* FLEXObjectExplorerFactory.m in Sources */ = {isa = PBXBuildFile; fileRef = 944F7432197B458C009AB039 /* FLEXObjectExplorerFactory.m */; };
@@ -97,6 +96,7 @@
 		946C6ECC1A759928006545C2 /* FLEXSystemLogTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 946C6ECA1A759928006545C2 /* FLEXSystemLogTableViewController.m */; };
 		946C6ECF1A7599C4006545C2 /* FLEXSystemLogMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 946C6ECE1A7599C4006545C2 /* FLEXSystemLogMessage.m */; };
 		94C681F31A3E941800E1936D /* FLEXLayerExplorerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 94C681F21A3E941800E1936D /* FLEXLayerExplorerViewController.m */; };
+		94CB48391A8EC6000054A905 /* FLEXMultilineTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 94CB48381A8EC6000054A905 /* FLEXMultilineTableViewCell.m */; };
 		D03647D919847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = D03647D819847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m */; };
 /* End PBXBuildFile section */
 
@@ -179,8 +179,6 @@
 		944F7428197B458C009AB039 /* FLEXClassExplorerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXClassExplorerViewController.m; sourceTree = "<group>"; };
 		944F7429197B458C009AB039 /* FLEXDefaultsExplorerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXDefaultsExplorerViewController.h; sourceTree = "<group>"; };
 		944F742A197B458C009AB039 /* FLEXDefaultsExplorerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXDefaultsExplorerViewController.m; sourceTree = "<group>"; };
-		944F742B197B458C009AB039 /* FLEXDescriptionTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXDescriptionTableViewCell.h; sourceTree = "<group>"; };
-		944F742C197B458C009AB039 /* FLEXDescriptionTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXDescriptionTableViewCell.m; sourceTree = "<group>"; };
 		944F742D197B458C009AB039 /* FLEXDictionaryExplorerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXDictionaryExplorerViewController.h; sourceTree = "<group>"; };
 		944F742E197B458C009AB039 /* FLEXDictionaryExplorerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXDictionaryExplorerViewController.m; sourceTree = "<group>"; };
 		944F742F197B458C009AB039 /* FLEXImageExplorerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXImageExplorerViewController.h; sourceTree = "<group>"; };
@@ -275,6 +273,8 @@
 		946C6ECE1A7599C4006545C2 /* FLEXSystemLogMessage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FLEXSystemLogMessage.m; path = "System Log/FLEXSystemLogMessage.m"; sourceTree = "<group>"; };
 		94C681F11A3E941800E1936D /* FLEXLayerExplorerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXLayerExplorerViewController.h; sourceTree = "<group>"; };
 		94C681F21A3E941800E1936D /* FLEXLayerExplorerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXLayerExplorerViewController.m; sourceTree = "<group>"; };
+		94CB48371A8EC6000054A905 /* FLEXMultilineTableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXMultilineTableViewCell.h; sourceTree = "<group>"; };
+		94CB48381A8EC6000054A905 /* FLEXMultilineTableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXMultilineTableViewCell.m; sourceTree = "<group>"; };
 		D03647D51984720F007D2A1B /* FLEXManager+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "FLEXManager+Private.h"; sourceTree = "<group>"; };
 		D03647D719847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FLEXGlobalsTableViewControllerEntry.h; sourceTree = "<group>"; };
 		D03647D819847248007D2A1B /* FLEXGlobalsTableViewControllerEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FLEXGlobalsTableViewControllerEntry.m; sourceTree = "<group>"; };
@@ -450,8 +450,6 @@
 				944F7428197B458C009AB039 /* FLEXClassExplorerViewController.m */,
 				944F7429197B458C009AB039 /* FLEXDefaultsExplorerViewController.h */,
 				944F742A197B458C009AB039 /* FLEXDefaultsExplorerViewController.m */,
-				944F742B197B458C009AB039 /* FLEXDescriptionTableViewCell.h */,
-				944F742C197B458C009AB039 /* FLEXDescriptionTableViewCell.m */,
 				944F742D197B458C009AB039 /* FLEXDictionaryExplorerViewController.h */,
 				944F742E197B458C009AB039 /* FLEXDictionaryExplorerViewController.m */,
 				944F742F197B458C009AB039 /* FLEXImageExplorerViewController.h */,
@@ -485,6 +483,8 @@
 				944F7441197B458C009AB039 /* FLEXRuntimeUtility.m */,
 				944F7442197B458C009AB039 /* FLEXUtility.h */,
 				944F7443197B458C009AB039 /* FLEXUtility.m */,
+				94CB48371A8EC6000054A905 /* FLEXMultilineTableViewCell.h */,
+				94CB48381A8EC6000054A905 /* FLEXMultilineTableViewCell.m */,
 			);
 			name = Utility;
 			path = ../Classes/Utility;
@@ -714,6 +714,7 @@
 				944F74B1197B458C009AB039 /* FLEXInstancesTableViewController.m in Sources */,
 				944F7497197B458C009AB039 /* FLEXUtility.m in Sources */,
 				535682B018F3670300BAAD62 /* AAPLDefaultToolbarViewController.m in Sources */,
+				94CB48391A8EC6000054A905 /* FLEXMultilineTableViewCell.m in Sources */,
 				535682BD18F3670300BAAD62 /* AAPLTintedToolbarViewController.m in Sources */,
 				943203FE1978F42F00E24DB3 /* AAPLCatalogTableTableViewController.m in Sources */,
 				944F748A197B458C009AB039 /* FLEXClassExplorerViewController.m in Sources */,
@@ -782,7 +783,6 @@
 				944F7495197B458C009AB039 /* FLEXResources.m in Sources */,
 				535682A918F3670300BAAD62 /* AAPLAlertViewController.m in Sources */,
 				944F74A6197B458C009AB039 /* FLEXIvarEditorViewController.m in Sources */,
-				944F748C197B458C009AB039 /* FLEXDescriptionTableViewCell.m in Sources */,
 				0149BFE2198FAFC700B90A1B /* FLEXFileBrowserSearchOperation.m in Sources */,
 				535682B218F3670300BAAD62 /* AAPLMasterViewController.m in Sources */,
 			);