Write One,Run Everywhere 之 RuntimeSize( )
没错这是宏定义
/** ** ** ** ** ** ** ** UI 适配 ** ** ** ** ** ** ** **/
#define K_ScreenW [UIScreen mainScreen].bounds.size.width
#define K_ScreenH [UIScreen mainScreen].bounds.size.height
#define K_IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define K_DefultSize (K_IS_IPHONE ? 375.00 : 768.00)
// 判断设配状态(竖屏 / 横屏)
#define K_DeviceISVertical ((K_ScreenH > K_ScreenW) ? 1 : 0)
#define K_DeviceDefultSize (K_DeviceISVertical ? K_ScreenH : K_ScreenW)
#define K_Scale (K_DeviceISVertical ? (K_ScreenW/K_DefultSize) : (K_ScreenH/K_DefultSize))
#define RuntimeSize(R) ((R)*K_Scale)
/** ** ** ** ** ** ** ** UI 适配 ** ** ** ** ** ** ** **/
使用方法
UIView *view = [UIView new];
view.backgroundColor = [UIColor blackColor];
view.frame = CGRectMake(((K_ScreenW - RuntimeSize(50))/2),
((K_ScreenH - RuntimeSize(100))/2),
RuntimeSize(50),
RuntimeSize(100));
[self.view addSubview:view];
注意:如果 APP 需要支持横屏和竖屏的话,当设备旋转时需要更新约束!
不定期更新...