2015-09-09 18 views

Trả lời

8

Chạy trên vấn đề này và đây là kết quả của tôi. Đây là một mớ hỗn độn thực sự.

Không có phông chữ hệ thống trung bình trên iOS7, họ đã thêm phông chữ đó trong iOS 8.2. Trên iOS7, sau một thời gian dài, nó sẽ chọn phông chữ đầu tiên theo thứ tự bảng chữ cái (Academy Engraved).

Điều thú vị là iOS 7 hệ thống đậm phông chữ thực sự là một phông chữ vừa Helvetica Neue:

(lldb) po [UIFont boldSystemFontOfSize:12] 
<UICTFont: 0x12c58f8b0> font-family: ".HelveticaNeueInterface-MediumP4"; font-weight: bold; font-style: normal; font-size: 12.00pt 

và systemFont là một Helvetica Neue thường xuyên.

Cách giải quyết cho iOS 7 là chọn phông chữ Hệ thống in đậm trong trình tạo giao diện, nó trông mỏng hơn khi chạy trên thiết bị iOS7 so với trên trình tạo giao diện. Thật không may, trên iOS8 và iOS9, nó thực sự trông đậm và không vừa ...

Tôi đã chuyển sang môi trường Helvetica-Neue cho những trường hợp không may nghĩa là tôi không khớp phông chữ hệ thống/San Francisco và Helvetica-Neue trong một số màn hình của tôi trên iOS 9. Không thể đợi để nhận được ánh sáng màu xanh lá cây để giảm hỗ trợ cho iOS7.

0

kiểm tra số phiên bản và nếu nó ít hơn 8 thay đổi font programatically trong viewDidLoad của bạn:

if !NSProcessInfo().isOperatingSystemAtLeastVersion(NSOperatingSystemVersion(majorVersion: 8, minorVersion: 0, patchVersion: 0)) { 
    //change font 
} 
4

tôi sử dụng phương pháp swizzling để sửa chữa lỗi iOS 7 này. Cách tiếp cận của tôi hoạt động tốt với Interface Builder.

UIFont + Swizzling.h

@import UIKit; 

@interface UIFont (UIFont_Swizzle) 

@end 

UIFont + Swizzling.m

#import "UIFont+Swizzle.h" 

@import ObjectiveC.runtime; 

@implementation UIFont (UIFont_Swizzle) 

+ (void)load { 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)]) return; 
     Class class = object_getClass((id)self); 

     SEL originalSelector = @selector(fontWithDescriptor:size:); 
     SEL swizzledSelector = @selector(swizzled_fontWithDescriptor:size:); 

     Method originalMethod = class_getClassMethod(class, originalSelector); 
     Method swizzledMethod = class_getClassMethod(class, swizzledSelector); 

     BOOL didAddMethod = class_addMethod(class, 
              originalSelector, 
              method_getImplementation(swizzledMethod), 
              method_getTypeEncoding(swizzledMethod)); 

     if (didAddMethod) { 
      class_replaceMethod(class, 
           swizzledSelector, 
           method_getImplementation(originalMethod), 
           method_getTypeEncoding(originalMethod)); 
     } else { 
      method_exchangeImplementations(originalMethod, swizzledMethod); 
     } 
    }); 
} 

+ (UIFont *)swizzled_fontWithDescriptor:(UIFontDescriptor *)descriptor size:(CGFloat)pointSize { 
    id usageAttribute = descriptor.fontAttributes[@"NSCTFontUIUsageAttribute"]; 

    if (!descriptor.fontAttributes[UIFontDescriptorNameAttribute] && 
     [usageAttribute isKindOfClass:[NSString class]] && 
     [usageAttribute isEqualToString:@"CTFontMediumUsage"]) { 
     descriptor = [descriptor fontDescriptorByAddingAttributes:@{UIFontDescriptorNameAttribute: @"HelveticaNeue-Medium"}]; 
    } 
    id font = [self swizzled_fontWithDescriptor:descriptor size:pointSize]; 

    return font; 
} 

@end 

đặc biệt cảm ơn tác giả Xtrace 's :)

+0

này nên là câu trả lời được chấp nhận –

Các vấn đề liên quan