ios IphoneX的一些适配,一些基础宏
1.基本属性
///获取安全区顶部高度 - (CGFloat)getSafeAreaTop{ if (@available(iOS 11.0, *)) { return self.view.safeAreaInsets.top;//44 } else { return 0.0; } } ///获取安全区底部高度 - (CGFloat)getSafeAreaBottom{ if (@available(iOS 11.0, *)) { return self.view.safeAreaInsets.bottom;//34 } else { return 0.0; } } ///获取window安全区底部高度 - (CGFloat)getWindowSafeAreaBottom{ if (@available(iOS 11.0, *)) { return [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;//34 } return 0.0; } ///获取window安全区顶部高度 - (CGFloat)getWindowSafeAreaTop{ if (@available(iOS 11.0, *)) { return [UIApplication sharedApplication].delegate.window.safeAreaInsets.top;//44 } return 0.0; }
2.一些基础宏
#define IphoneX [[DeviceDataLibrery sharedLibrery] isIphoneX] #define UIColorFromRGBA(rgbValue, alphaValue) [UIColor \ colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \ green:((float)((rgbValue & 0x00FF00) >> 8))/255.0 \ blue:((float)(rgbValue & 0x0000FF))/255.0 \ alpha:alphaValue] #define UIColorFromRGB(rgbValue) UIColorFromRGBA(rgbValue, 1.0) #define UIScreenWidth ([UIScreen mainScreen].bounds.size.width) #define UIScreenHeight ([UIScreen mainScreen].bounds.size.height) // MARK: 系统宏定义 #define IOS11 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 11.0) #define IOS10 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 10.0) #define IOS9 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 9.0) #define IOS8 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.0) #define IOS8_2 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 8.2) #define IOS7 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7.0) #define IOS7_1 ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 7.1) // 是否是模拟器 #define isSimulator ([DeviceUtil hardware] == SIMULATOR) #define ProjectTitle @"应用名字" #define AccessPhoto [NSString stringWithFormat:@"请在iPhone的\"设置-隐私-照片\"选项中,允许%@访问您的照片",ProjectTitle] #define AccessCamera [NSString stringWithFormat:@"请在iPhone的\"设置-隐私-相机\"选项中,允许%@访问您的相机",ProjectTitle] #define AccessLocation [NSString stringWithFormat:@"请在iPhone的\"设置-隐私-定位服务\"选项中,允许%@获取您的地理位置",ProjectTitle] #define AccessMicrophone [NSString stringWithFormat:@"请在iPhone的\"设置-隐私-麦克风\"选项中,允许%@使用您的麦克风",ProjectTitle] #define NormalTeamErrorTip [NSString stringWithFormat:@"****%@不支持普通群****",ProjectTitle] #define FileTransferTip [NSString stringWithFormat:@"在这里可以将照片、文件发送到电脑端%@",ProjectTitle]