美文网首页
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开发中常用的宏

    以下为iOS开发中常用宏: 引用:ios开发常用的宏,大家一起来收集 参考:ios开发常用的宏,大家一起来收集~

  • iOS开发常用的工具类和宏定义

    iOS开发常用的工具类和宏定义 开发总结的工具类和宏 https://github.com/xiaoChen66...

  • iOS 常用宏定义

    iOS 开发中使用一些常用宏定义可以大大提高开发效率,提高代码的重用性.以下是一些常用的宏定义: 像这些宏定义,在...

  • iOS开发中常用到的宏

    大家都是知道使用宏不仅方便,而且可以提高开发效率。下面总结了iOS开发过程中的一些常用宏。

  • 开发常用宏 - iOS

    开发中很多常用的方法会在很多地方被多次使用到,因此为了提升开发效率,特此将其配置为宏,从而使用起来更加得心应手,以...

  • iOS开发常用宏

    Debug与Release 自定义NSLog 屏幕宽度 颜色设置 沙盒路径

  • iOS开发常用宏

    设备 系统 设置Debug模式下打印log,release模式下不打印 颜色 字体大小(常规/粗体) 常用方法 单例

  • ios开发常用宏

    /** 屏幕宽度 */ #define eDeviceWidth [UIScreen mainScreen].bo...

  • iOS 开发常用宏

    引子: 今天一个前辈解决了我纠结了很久的问题,具体点说就是怎么在cell里面获取父视图的navigationCon...

  • iOS开发常用宏

    //字符串是否为空#define kStringIsEmpty(str) ([str isKindOfClass:...

网友评论

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

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