这是我目前的宏定义
//
// CBBasicHeader.h
// ABCreditApp
//
// Created by caobo56 on 2017/2/14.
// Copyright © 2017年 caobo56. All rights reserved.
//
#ifndef CBBasicHeader_h
#define CBBasicHeader_h
#define UI_IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define UI_IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define UI_IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define SCREENSIZE_IS_35 (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height < 568.0)
#define SCREENSIZE_IS_40 (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0)
#define SCREENSIZE_IS_47 (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0)
#define SCREENSIZE_IS_55 (UI_IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0 || [[UIScreen mainScreen] bounds].size.width == 736.0)
//判断iPHoneXr
#define SCREENSIZE_IS_XR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !UI_IS_IPAD : NO)
//判断iPHoneX、iPHoneXs
#define SCREENSIZE_IS_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !UI_IS_IPAD : NO)
#define SCREENSIZE_IS_XS ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !UI_IS_IPAD : NO)
//判断iPhoneXs Max
#define SCREENSIZE_IS_XS_MAX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !UI_IS_IPAD : NO)
#define IS_IPhoneX_All ([UIScreen mainScreen].bounds.size.height == 812 || [UIScreen mainScreen].bounds.size.height == 896)
//状态栏、导航栏、标签栏高度
#define Height_StatusBar [[UIApplication sharedApplication] statusBarFrame].size.height
#define Height_NavBar 44.0f
#define Height_TopBar (Height_StatusBar + Height_NavBar)
#define Height_TapBar (IS_IPhoneX_All ? 83.0f:49.0f)
#define Height_BottomSafe (IS_IPhoneX_All? 34.0f:0.0f)
#define SCREEN_HEIGHTL [UIScreen mainScreen].bounds.size.height
#define SCREEN_WIDTHL [UIScreen mainScreen].bounds.size.width
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
#define RGB16(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define RGBAlpha(rgbValue,alphaValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:alphaValue]
#define WeakSelf __weak typeof(self) weakSelf = self;
#endif /* CBBasicHeader_h */
//判断屏幕大小是否为iPHoneX、iPHoneXs,这个我写的一样的,因为的确屏幕大小是一样的,这个对UI适配是足够的。
之前的版本,问题还是有一些的,吸取了评论区的一些批评与建议,谢谢!
下面是最初的版本
————————————————————————————————————————————
关于顶部导航栏
#define SCREEN_HEIGHTL [UIScreen mainScreen].bounds.size.height
#define SCREEN_WIDTHL [UIScreen mainScreen].bounds.size.width
#define Height_StatusBar [[UIApplication sharedApplication] statusBarFrame].size.height
#define Height_NavBar self.navigationController.navigationBar.frame.size.height
#define Height_TopBar (Height_StatusBar+Height_NavBar)
//适配iPhoneXS Max,iPhoneXS,iPhoneXR
判断是否为 iPhoneXS Max,iPhoneXS,iPhoneXR,iPhoneX
#define KIsiPhoneX ((int)((SCREEN_HEIGHTL/SCREEN_WIDTHL)*100) == 216)?YES:NO
//判断是否为 iPhoneXS Max,iPhoneXS,iPhoneXR,iPhoneX
我是根据 iPhoneXS Max,iPhoneXS,iPhoneXR,iPhoneX 的宽高比近似做的判断。
//XSM SCREEN_HEIGHTL = 896.000000,SCREEN_WIDTHL = 414.000000 2.1642512077
//XS SCREEN_HEIGHTL = 812.000000,SCREEN_WIDTHL = 375.000000 2.1653333333
//XR SCREEN_HEIGHTL = 896.000000,SCREEN_WIDTHL = 414.000000 2.1642512077
NSLog(@"SCREEN_HEIGHTL = %f,SCREEN_WIDTHL = %f",SCREEN_HEIGHTL,SCREEN_WIDTHL);
NSLog(@"%d",(int)((SCREEN_HEIGHTL/SCREEN_WIDTHL)*100));
if ((int)((SCREEN_HEIGHTL/SCREEN_WIDTHL)*100) == 216) {
NSLog(@"YES,we can use it!");
}else{
NSLog(@"NO,we can`t use it!");
}