0.在appdelegate中声明两个变量
@property (nonatomic , assign)float autoSizeScaleX;
@property (nonatomic , assign)float autoSizeScaleY;
1.在appdelegate.m中初始化这两个变量
/// 获取到delegate
AppDelegate *delegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
/// 这里是基于苹果6sp的尺寸为标准,其他屏幕按比例缩放
if (kScreenHeight > 苹果6sp){
delegate.autoSizeScaleX = 1;
delegate.autoSizeScaleY = 1;
} else {
delegate.autoSizeScaleX = kScreenWidth / 375;
delegate.autoSizeScaleY = kScreenHeight / 667;
}
2.在pch中 获取到appdelegate
#define ZCAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)
3.做成你自己的宏,调用的时候直接adaptX(num)或者adaptY(num)
#define adaptX(num) num *ZCAppDelegate.autoSizeScaleX
#define adaptY(num) num *ZCAppDelegate.autoSizeScaleY
4.最后别忘了把appdelegate包含在pch文件里
网友评论