創(chuàng)建一個(gè) UIFont 的分類
#import <objc/runtime.h>
#define UISize_With 375 //設(shè)計(jì)參考的屏幕寬度
@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
搞定!