我做的功能是设置字体只交换一次就好了
+(void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
// 1.systemFontOfSize
Method orignalMethod1 = class_getClassMethod(class, @selector(systemFontOfSize:));
Method myMethod1 = class_getClassMethod(class, @selector(mySystemFontOfSize:));
method_exchangeImplementations(orignalMethod1, myMethod1);
// 2.boldSystemFontOfSize
Method orignalMethod2 = class_getInstanceMethod(class, @selector(boldSystemFontOfSize:));
Method myMethod2 = class_getInstanceMethod(class, @selector(myBoldSystemFontOfSize:));
method_exchangeImplementations(orignalMethod2, myMethod2);
});
}
\
+(UIFont *)mySystemFontOfSize:(CGFloat)fontSize {
UIFont *font = [UIFont fontWithName:[GLJInternationHelper isLangZH]?CustomFontName:CustomFontName1 size:fontSize];
if (!font) {
return [self mySystemFontOfSize:fontSize];
}
return font;
}
\
+(UIFont *)myBoldSystemFontOfSize:(CGFloat)fontSize {
UIFont *font = [UIFont fontWithName:CustomBoldFontName size:fontSize];
if (!font) {
return [self myBoldSystemFontOfSize:fontSize];
}
return font;
} 如果要完整实现交换字体的功能,还需要添加ttf文件。