创建一个 UIFont 的分类
#import <objc/runtime.h>
#define UISize_With 375 //设计参考的屏幕宽度
@implementation UIFont (JDRuntimeFont)
+(void)load{
//获取替换后的类方法
Method newMethod =class_getClassMethod([self class], @selector(adjustFont:));
//获取需要替换的类方法
Method method = class_getClassMethod([self class],@selector(systemFontOfSize:));
//交换方法
method_exchangeImplementations(newMethod, method);
}
+(UIFont *)adjustFont:(CGFloat)fontSize{
UIFont *newFont=nil;
newFont = [UIFont adjustFont:fontSize * [UIScreen mainScreen].bounds.size.width/375];
return newFont;
}
@end
搞定!