一般现在都是用宏来弄,但是之前的项目想适配又觉得太麻烦所以直接用runtime来交换一下方法做下过滤处理。
弄个UIFont分类
// UIFont (RuntimeFit)实现
+ (void)load {
Method selfMethod = class_getClassMethod([self class], @selector(runtimeFitFont:));
Method systenMethod = class_getClassMethod([self class], @selector(systemFontOfSize:));
method_exchangeImplementations(selfMethod, systenMethod);
}
+ (UIFont *)runtimeFitFont:(CGFloat)fontSize {
UIFont *fitFont = nil;
//这里并不会造成递归调用,方法已经被交换
fitFont = [UIFont runtimeFitFont:fontSize * (SCREEN_WIDTH / 375 )];
return fitFont;
}