Преглед изворни кода

Work around deprecation warnings when deployment target >= 7.0

We still support back to deployment target 6.0, but this is nicer for users of the library that no longer support 6.0.
Ryan Olson пре 12 година
родитељ
комит
213d9769d2

+ 2 - 2
Classes/Editing/Argument Input Views/FLEXArgumentInputView.m

@@ -75,7 +75,7 @@
 {
     CGFloat verticalLayoutGuide = 0;
     if (self.showsTitle) {
-        CGFloat titleHeight = ceil([self.title sizeWithFont:[[self class] titleFont] constrainedToSize:self.bounds.size].height);
+        CGFloat titleHeight = [self.titleLabel sizeThatFits:self.bounds.size].height;
         verticalLayoutGuide = titleHeight + [[self class] titleBottomPadding];
     }
     return verticalLayoutGuide;
@@ -127,7 +127,7 @@
     
     if ([self.title length] > 0) {
         CGSize constrainSize = CGSizeMake(size.width, CGFLOAT_MAX);
-        height += ceil([self.title sizeWithFont:[[self class] titleFont] constrainedToSize:constrainSize].height);
+        height += ceil([self.titleLabel sizeThatFits:constrainSize].height);
         height += [[self class] titleBottomPadding];
     }
     

+ 2 - 3
Classes/Editing/FLEXFieldEditorView.m

@@ -157,7 +157,6 @@
 {
     CGFloat horizontalPadding = [[self class] horizontalPadding];
     CGFloat verticalPadding = [[self class] verticalPadding];
-    UIFont *font = [[self class] labelFont];
     CGFloat dividerLineHeight = [[self class] dividerLineHeight];
     
     CGFloat height = 0;
@@ -165,11 +164,11 @@
     CGSize constrainSize = CGSizeMake(availableWidth, CGFLOAT_MAX);
     
     height += verticalPadding;
-    height += ceil([self.targetDescription sizeWithFont:font constrainedToSize:constrainSize].height);
+    height += ceil([self.targetDescriptionLabel sizeThatFits:constrainSize].height);
     height += verticalPadding;
     height += dividerLineHeight;
     height += verticalPadding;
-    height += ceil([self.fieldDescription sizeWithFont:font constrainedToSize:constrainSize].height);
+    height += ceil([self.fieldDescriptionLabel sizeThatFits:constrainSize].height);
     height += verticalPadding;
     height += dividerLineHeight;
     height += verticalPadding;

+ 8 - 7
Classes/Explorer Toolbar/FLEXToolbarItem.m

@@ -7,10 +7,11 @@
 //
 
 #import "FLEXToolbarItem.h"
+#import "FLEXUtility.h"
 
 @interface FLEXToolbarItem ()
 
-@property (nonatomic, copy) NSString *title;
+@property (nonatomic, copy) NSAttributedString *attributedTitle;
 @property (nonatomic, strong) UIImage *image;
 
 @end
@@ -21,7 +22,6 @@
 {
     self = [super initWithFrame:frame];
     if (self) {
-        self.titleLabel.font = [[self class] titleFont];
         self.backgroundColor = [[self class] defaultBackgroundColor];
         [self setTitleColor:[[self class] defaultTitleColor] forState:UIControlStateNormal];
         [self setTitleColor:[[self class] disabledTitleColor] forState:UIControlStateDisabled];
@@ -32,9 +32,10 @@
 + (instancetype)toolbarItemWithTitle:(NSString *)title image:(UIImage *)image
 {
     FLEXToolbarItem *toolbarItem = [self buttonWithType:UIButtonTypeCustom];
-    toolbarItem.title = title;
+    NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:[self titleAttributes]];
+    toolbarItem.attributedTitle = attributedTitle;
     toolbarItem.image = image;
-    [toolbarItem setTitle:title forState:UIControlStateNormal];
+    [toolbarItem setAttributedTitle:attributedTitle forState:UIControlStateNormal];
     [toolbarItem setImage:image forState:UIControlStateNormal];
     return toolbarItem;
 }
@@ -42,9 +43,9 @@
 
 #pragma mark - Display Defaults
 
-+ (UIFont *)titleFont
++ (NSDictionary *)titleAttributes
 {
-    return [UIFont systemFontOfSize:12.0];
+    return @{NSFontAttributeName : [FLEXUtility defaultFontOfSize:12.0]};
 }
 
 + (UIColor *)defaultTitleColor
@@ -110,7 +111,7 @@
 {
     // Bottom aligned and centered.
     CGRect titleRect = CGRectZero;
-    CGSize titleSize = ([self.title sizeWithFont:[[self class] titleFont] constrainedToSize:contentRect.size]);
+    CGSize titleSize = [self.attributedTitle boundingRectWithSize:contentRect.size options:0 context:nil].size;
     titleSize = CGSizeMake(ceil(titleSize.width), ceil(titleSize.height));
     titleRect.size = titleSize;
     titleRect.origin.y = contentRect.origin.y + CGRectGetMaxY(contentRect) - titleSize.height;

+ 4 - 1
Classes/Object Explorers/FLEXDescriptionTableViewCell.m

@@ -73,7 +73,10 @@
     UIEdgeInsets labelInsets = [self labelInsets];
     labelWidth -= (labelInsets.left + labelInsets.right);
     
-    CGFloat preferredLabelHeight = ceil([text sizeWithFont:[self labelFont] constrainedToSize:CGSizeMake(labelWidth, CGFLOAT_MAX)].height);
+    // 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;