mam ustawienie System Medium
czcionki na storyboard tak:inny system Średnia czcionka na iOS 7
I to jest wynik dla iOS 8
:
Ale iOS 7
pokazuje inną (dziwną) czcionkę:
Czy coś nie tak?
mam ustawienie System Medium
czcionki na storyboard tak:inny system Średnia czcionka na iOS 7
I to jest wynik dla iOS 8
:
Ale iOS 7
pokazuje inną (dziwną) czcionkę:
Czy coś nie tak?
Działa również na ten problem i to są moje wnioski. To prawdziwy bałagan.
W systemie iOS7 nie ma czcionki systemu średniego, dodano ją w systemie iOS 8.2. Na iOS7, po długim opóźnieniu, wybiera pierwszą czcionkę w kolejności alfabetycznej (Academy Engraved).
ciekawe czcionka iOS 7 pogrubione system jest rzeczywiście czcionki Helvetica Neue Średni:
(lldb) po [UIFont boldSystemFontOfSize:12]
<UICTFont: 0x12c58f8b0> font-family: ".HelveticaNeueInterface-MediumP4"; font-weight: bold; font-style: normal; font-size: 12.00pt
i systemFont jest regularny Helvetica Neue.
Rozwiązaniem dla systemu iOS 7 jest wybranie czcionki pogrubienia systemu w narzędziu do tworzenia interfejsów, która wygląda na cieńszą, gdy jest uruchomiona na urządzeniu z systemem iOS7, niż w programie budującym interfejs. Niestety, na iOS8 i iOS9 wygląda naprawdę odważnie, a nie średnio ...
Skończyło się przejście na Helvetica-Neue Medium dla tych przypadków, które niestety oznaczają, że mam niedopasowanie czcionki systemowej/San Francisco i Helvetica-Neue na niektórych moich ekranach w iOS 9. Nie mogę się doczekać, aż zielone światło zwolni obsługę iOS7.
sprawdzić numer wersji i jeśli jej mniej niż 8 zmiana czcionki programowo w viewDidLoad:
if !NSProcessInfo().isOperatingSystemAtLeastVersion(NSOperatingSystemVersion(majorVersion: 8, minorVersion: 0, patchVersion: 0)) {
//change font
}
używam metody swizzling naprawić ten błąd iOS 7. Moje podejście działa dobrze z narzędziem do tworzenia interfejsu.
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
Specjalne podziękowania dla Xtrace „s twórcy :)
powinno to być zaakceptowane odpowiedź –