美文网首页
iOS开发常用的宏

iOS开发常用的宏

作者: 程序员学哥 | 来源:发表于2019-08-15 23:01 被阅读0次
    /** -----------------------------------------UIScreen----------------------------------------------------------- **/
    
    #pragma mark - UIScreen
    #define KIPhone4                    ([UIScreen mainScreen].bounds.size.height == 480)
    #define KIPhone5                    ([UIScreen mainScreen].bounds.size.height == 568)
    #define KIPhone6                    ([UIScreen mainScreen].bounds.size.height == 667)
    #define KIPhone6P                   ([UIScreen mainScreen].bounds.size.height == 736)
    #define KIPhoneX                    ((([[UIScreen mainScreen] nativeBounds].size.height == 2436) || ([[UIScreen mainScreen] nativeBounds].size.height == 2688) || ([[UIScreen mainScreen] nativeBounds].size.height == 1792) || ([[UIScreen mainScreen] nativeBounds].size.height == 1624)) ? YES : NO)
    
    #define kStatusBarHeight            ((KIPhoneX)?44:20)
    #define kNavbarHeight               ((KIPhoneX)?88:64)
    #define kTabBarHeight               ((KIPhoneX)?83:49)
    #define kTabBarSafe                 ((KIPhoneX)?34:0)
    
    /** 机器类型 **/
    #define KIPhoneX                   ((([[UIScreen mainScreen] nativeBounds].size.height == 2436) || ([[UIScreen mainScreen] nativeBounds].size.height == 2688) || ([[UIScreen mainScreen] nativeBounds].size.height == 1792) || ([[UIScreen mainScreen] nativeBounds].size.height == 1624)) ? YES : NO)
    
    #define KISPhoneX                  (([[UIScreen mainScreen] bounds].size.height == 812) ? YES : NO)
    #define KISPhoneXR                 (([[UIScreen mainScreen] bounds].size.height == 896) ? YES : NO)
    #define KISPhoneXS_MAX             (([[UIScreen mainScreen] bounds].size.height == 896) ? YES : NO)
    #define KISPhoneFive               (([[UIScreen mainScreen] bounds].size.width < 375) ? YES : NO)
    
    /** 屏幕宽度 **/
    #define kScreenHeight               [UIScreen mainScreen].bounds.size.height
    #define kScreenWidth                [UIScreen mainScreen].bounds.size.width
    
    /** 屏幕尺寸 **/
    #define k_ScreenHeight_480          kScreenHeight == 480 //iphone4、4s
    #define k_ScreenHeight_568          kScreenHeight == 568 //iphone5、5s
    #define k_ScreenHeight_667          kScreenHeight == 667 //iphone6、6s
    #define k_ScreenHeight_736          kScreenHeight == 736 //iphone6plus
    #define k_ScreenHeight_812          kScreenHeight == 812.0 //iphone X
    
    /** 比率 **/
    #define KWidthRatio                 (kScreenHeight == 812.0 ? 375.0/375.0 : kScreenWidth/375.0)
    #define KHeightRatio                (kScreenHeight == 812.0 ? 700.0/667.0 : kScreenHeight/667.0)
    
    
    /** ------------------------------------------Device------------------------------------------------------------ **/
    #pragma mark - Device
    /** 设备名 **/
    #define kDevice_Name                [[UIDevice alloc] init].name
    #define KDevice_code                ([[[UIDevice currentDevice] identifierForVendor] UUIDString])
    #define KVersion_Code               [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleShortVersionString"]
    #define KDevice_Model               [[UIDevice alloc] init].model
    #define KDevice_SystemVersion       [[UIDevice alloc] init].systemVersion
    #define KDevice_Name                [[UIDevice alloc] init].name
    #define KDevice_SystemName          [[UIDevice alloc] init].systemName
    #define KVersion_Name               [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleVersion"]
    #define KBundle_Name                [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleIdentifier"]
    #define KApp_Name                   [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleDisplayName"]
    #define KISIOS9                     ([[UIDevice currentDevice].systemVersion intValue]>=9?YES:NO)
    #define KISIOS10                    ([[UIDevice currentDevice].systemVersion intValue]>=10?YES:NO)
    #define KISIOS11                    ([[UIDevice currentDevice].systemVersion intValue]>=11?YES:NO)
    
    
    /** -------------------------------------------Color----------------------------------------------------------- **/
    #pragma mark - Color
    /** RGBA创建UIColor **/
    #define kRGBA(r, g, b, a)           [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
    #define rgba(r, g, b, a)            [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
    #define KRandomColor                [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0];
    
    /** -------------------------------------------self block饮用----------------------------------------------------------- **/
    #pragma mark - weakSelf
    /** RGBA创建UIColor **/
    #define KWeakSelf                   @weakify(self)
    #define KStrongSelf                 @strongify(self)
    #define KBlockWeakSelf              __weak typeof(self) weakSelf = self;

    相关文章

      网友评论

          本文标题:iOS开发常用的宏

          本文链接:https://www.haomeiwen.com/subject/mfcxsctx.html