扩展UIfont,然后使用Runtime替换方法
#import "UIFont+YXGFont.h"
#import <objc/runtime.h>
#define SCREEN_WIDTH 375 //默认屏幕宽度
@implementation UIFont (YXGFont)
+(void)load{
//获取替换后的类方法
Method newMethod = class_getClassMethod([self class], @selector(adjustFontSize:));
//获取需要替换的类方法
Method method = class_getClassMethod([self class], @selector(systemFontOfSize:));
//交换方法
method_exchangeImplementations(newMethod, method);
}
+(UIFont *)adjustFontSize:(CGFloat)fontSize{
UIFont *newFont=nil;
newFont = [UIFont adjustFont:fontSize * [UIScreen mainScreen].bounds.size.width/SCREEN_WIDTH];
return newFont;
}
@end