2015-09-09 12 views
10

Böyle film şeridinde bir System Medium yazı ayarlıyorum:Farklı Sistem Orta yazı 7

enter image description here

Ve bu iOS 8 sonucu şudur:

enter image description here

Ama iOS 7 (garip) yazı tipi farklı bir font gösteriyor:

enter image description here

Yanlış bir şey mi ayarlıyorum?

cevap

8

Bu problem üzerinde de çalışıyorum ve bu benim bulgularım. Bu gerçek bir karmaşa.

iOS7'de Orta sistem yazı tipi yok, iOS 8.2'de eklediler. IOS7'de, uzun bir gecikmeden sonra, ilk yazı tipini alfabetik sırada seçer (Academy Engraved).

İlginç iOS 7 kalın sistem yazı aslında bir Orta Helvetica Neue font:

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

ve systemFont düzenli Helvetica Neue olduğunu.

iOS 7 için Geçici Çözüm, arayüz oluşturucusunda Sistem Kalın yazı tipini seçmektir; bir iOS7 aygıtında arayüz oluşturucusundan olduğundan daha zayıf görünür. Ne yazık ki, iOS8 ve iOS9'da, gerçekten de cesur ve orta gibi görünmüyor…

Maalesef sistem yazı tipi/San Francisco ve Helvetica-Neue ile eşleşmeyen bir sisteme sahip olduğum durumlar için Helvetica-Neue Medium'a geçtim. iOS 9'daki bazı ekranlarımda. iOS7 desteğini düşürmek için yeşil ışık almak için sabırsızlanıyorum.

0

onay sürüm numarası ve programlı bir şekilde viewDidLoad onun az 8 değişim ise font:

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

bu iOS 7 hatayı düzeltmek için yöntem swizzling kullanın. Benim yaklaşımım, Arayüz Oluşturucu ile iyi çalışıyor.

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 

Özel teşekkürler Xtrace 'ın yaratıcısı :)

+0

Bu kabul cevap olmalıdır için –

İlgili konular