Было два подхода, которые мы нашли на нашем пути: 1. Использование метода swizzling 2. Создание категории для UIFont и переопределение методов
#import "SystemFontOverride.h"
@implementation UIFont (SystemFontOverride)
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-protocol-method-implementation"
// do your override
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize {
UIFont *font = [UIFont fontWithName:@"Raleway-Regular" size:fontSize];
if (font != nil) {
return font;
}
return [UIFont systemFontOfSize:fontSize];
}
+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize {
UIFont *font = [UIFont fontWithName:@"Raleway-Bold" size:fontSize];
if (font != nil) {
return font;
}
return [UIFont systemFontOfSize:fontSize];
}
+ (UIFont *)italicSystemFontOfSize:(CGFloat)fontSize {
UIFont *font = [UIFont fontWithName:@"Raleway-Italic" size:fontSize];
if (font != nil) {
return font;
}
return [UIFont systemFontOfSize:fontSize];
}
+ (UIFont *)systemFontOfSize:(CGFloat)fontSize weight:(UIFontWeight)weight NS_AVAILABLE_IOS(8_2) {
NSString *fontName;
if (weight == UIFontWeightSemibold) {
fontName = @"Raleway-SemiBold";
} else if (weight == UIFontWeightBold) {
fontName = @"Raleway-Bold";
} else if (weight == UIFontWeightRegular){
fontName = @"Raleway-Regular";
} else if (weight == UIFontWeightMedium){
fontName = @"Raleway-Medium";
} else if (weight == UIFontWeightThin){
fontName = @"Raleway-Thin";
} else if (weight == UIFontWeightBlack) {
fontName = @"Raleway-Black";
}
if (fontName != nil && fontName.length > 0) {
UIFont *font = [UIFont fontWithName:fontName size:fontSize];
if (font != nil) {
return font;
}
}
return [UIFont systemFontOfSize:fontSize];
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
if (self) {
BOOL result = [coder containsValueForKey:@"UIFontDescriptor"];
if (result) {
UIFontDescriptor *descriptor = [coder decodeObjectForKey:@"UIFontDescriptor"];
NSString *fontName;
if ([descriptor.fontAttributes[@"NSCTFontUIUsageAttribute"] isEqualToString:@"CTFontRegularUsage"]) {
fontName = @"Raleway-Regular";
}
else if ([descriptor.fontAttributes[@"NSCTFontUIUsageAttribute"] isEqualToString:@"CTFontEmphasizedUsage"]) {
fontName = @"Raleway-Bold";
}
else if ([descriptor.fontAttributes[@"NSCTFontUIUsageAttribute"] isEqualToString:@"CTFontObliqueUsage"]) {
fontName = @"Raleway-Italic";
}
else {
fontName = descriptor.fontAttributes[@"NSFontNameAttribute"];
}
return [UIFont fontWithName:fontName size:descriptor.pointSize];
}
}
return self;
}
#pragma clang diagnostic pop
@end
Еще один улов был переопределить systemFont, который установлен в раскадровкенам нужно было реализовать initWithCoder.
Спасибо за все ваши ответы выше, но я нашел этот способ более эффективным и полным охватом за меньшее время.Теперь я могу создать свой enum шрифта и установить все, что я хочу изменить, не беспокоясь о том, установил ли я шрифт из раскадровки или код.