- 1、字体适配思路
写个UIFont(category),在category里面重写+(void)load方法,采用method_exchangeImplementations 进行方法替换,具体代码如下操作:
///自定义字体,缩放等相关适配信息
+ (UIFont *)custom_systemFontOfSize:(CGFloat)fontSize{
//获取设备屏幕宽度,并计算出比例scale
CGFloat width = [[UIScreen mainScreen] bounds].size.width;
CGFloat scale = width/375.0;
//注意:系统的方法名已变成了自定义的方法名
return [UIFont custom_systemFontOfSize:fontSize * scale];
}
//重写
+ (void)load{
//获取系统方法
Method sytemMethod = class_getClassMethod([UIFont class], @selector(systemFontOfSize:));
//获取自定义方法
Method customMethod = class_getClassMethod([UIFont class], @selector(custom_systemFontOfSize:));
//交换
method_exchangeImplementations(sytemMethod, customMethod);
}
2、制作比较细腻的引导层,一般引导层,直接在window上加个UIView搞就完事了,做好适配就行
新增category,通过objc_setAssociatedObjec