创建font的分类,利用runtime中exchange方法实现:
+ (UIFont *)adapt_fontWithName:(NSString *)fontName size:(CGFloat)fontSize {
if (![UIFont adapt_fontWithName:fontName size:fontSize]) {
return [UIFont systemFontOfSize:fontSize];
}
return [UIFont adapt_fontWithName:fontName size:fontSize];
}
+ (void)load {
Method fontNameMethod = class_getClassMethod([UIFont class], @selector(fontWithName:size:));
Method adaptNameMethod = class_getClassMethod([UIFont class], @selector(adapt_fontWithName:size:));
method_exchangeImplementations(fontNameMethod, adaptNameMethod);
}
网友评论