本文主要介绍如何简单快捷的使用屏幕适配,快速按照设计图尺寸布局
简单使用
在最初的地方AppDelegate里面调用 [UIResponder kj_adaptModelType:KJAdaptTypeIPhone6];
然后在需要适配的地方 替换 CGRectMake 为 KJAdaptRectMake
view.frame = CGRectMake(0, 0, 10, 10);
替换为
view.frame = KJAdaptRectMake(0, 0, 10, 10);
即可完成简单的屏幕比例适配
简单描述思路
1.声明设计图手机类型
/// 适配类型 设计图类型
typedef NS_ENUM(NSInteger, KJAdaptModelType) {
KJAdaptTypeIPhone4 = 0, /// 3.5英寸,320 x 480pt
KJAdaptTypeIPhone5, /// 4.0英寸,320 x 568pt
KJAdaptTypeIPhone6, /// 4.7英寸,375 x 667pt
KJAdaptTypeIPhone6P, /// 5.5英寸,414 x 736pt
KJAdaptTypeIPhoneX, /// 5.8英寸,375 x 812pt
KJAdaptTypeIPhoneXR, /// 6.1英寸,414 x 896pt
KJAdaptTypeIPhoneXSMax, /// 6.5英寸,414 x 896pt
// KJAdaptTypeIPhone12Mini,/// 5.4英寸,
// KJAdaptTypeIPhone12ProMax,/// 6.7英寸,
};
2.委托确定设计图的类型
@protocol KJResponderAdaptProtocol <NSObject>
/// 设计图机型,只需要在最初的地方调用一次即可
+ (void)kj_adaptModelType:(KJAdaptModelType)type;
@end
+ (KJAdaptModelType)adaptType{
return (KJAdaptModelType)[objc_getAssociatedObject(self, @selector(adaptType)) intValue];
}
+ (void)setAdaptType:(KJAdaptModelType)adaptType{
objc_setAssociatedObject(self, @selector(adaptType), @(adaptT