Write One,Run Everywhere 之 RuntimeSize( )
沒(méi)錯(cuò)這是宏定義
/** ** ** ** ** ** ** ** 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)
// 判斷設(shè)配狀態(tài)(豎屏 / 橫屏)
#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 需要支持橫屏和豎屏的話,當(dāng)設(shè)備旋轉(zhuǎn)時(shí)需要更新約束削罩!
不定期更新...