美文网首页iOS Developer
iOS开发 我的宏定义文件

iOS开发 我的宏定义文件

作者: 嫌疑人zx | 来源:发表于2018-01-03 10:56 被阅读164次

刚找了一份新工作,分享一份我在老东家椰视用了2年的宏定义文件吧,中间修改过很多次,就目前而言,我觉得还算比较成熟吧,有啥建议可以在留言区评论!

common.h

//plist文件常量 ——>路径
#define DocumentsDirectory [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]

//历史搜索记录
#define HISTORYSEARCHFILE [DocumentsDirectory stringByAppendingPathComponent:@"historySearch.plist"]

//获取appDelegates类
#define ApplicationDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)

// 1.判断是否为iOS8
#define iOS8 ([[UIDevice currentDevice].systemVersion doubleValue] >= 8.0)
// 2.判断是否为iOS9
#define iOS9 ([[UIDevice currentDevice].systemVersion doubleValue] >= 9.0)
// 3.判断是否为iOS10
#define iOS10 ([[UIDevice currentDevice].systemVersion doubleValue] >= 10.0)
// 4.判断是否为iOS11
#define iOS11 ([[UIDevice currentDevice].systemVersion doubleValue] >= 11.0)
// 5.判断是否为iOS12
#define iOS12 ([[UIDevice currentDevice].systemVersion doubleValue] >= 12.0)
// 6.判断是否为iOS13
#define iOS13 ([[UIDevice currentDevice].systemVersion doubleValue] >= 13.0)

//手机型号和平板
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)

#define IS_IPHONE_4 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)480) < DBL_EPSILON)
#define IS_IPHONE_5 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)568) < DBL_EPSILON)
#define IS_IPHONE_6 (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)667) < DBL_EPSILON)
#define IS_IPHONE_6P (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)736) < DBL_EPSILON)
#define IS_IPHONE_X (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)812) < DBL_EPSILON) || (fabs((double)[[UIScreen mainScreen]bounds].size.height - (double)896) < DBL_EPSILON)

// 1.获得RGB颜色
#define YTHColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]
#define YTHColorAlpha(r, g, b ,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]

// 2.用代码形式代码
#define UIColorFromRGBValue(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]

// 3.屏幕宽高
#define KScreenHp [[UIScreen mainScreen] bounds].size.height*1.0 // 屏幕高度
#define KScreenWp [[UIScreen mainScreen] bounds].size.width*1.0 // 屏幕宽度

#define KScreenH MAX(KScreenHp,KScreenWp) // 屏幕高度
#define KScreenW MIN(KScreenHp,KScreenWp)// 屏幕宽度

// 4.导航栏/工具栏/状态栏高度
#define kNavigationBarH 44
#define kStatusBarH [[UIApplication sharedApplication] statusBarFrame].size.height//顶部状态栏高度
#define kToolBarH (IS_IPHONE_X ? 83 : 49)//底部工具栏高度
#define kNoToolBarX (IS_IPHONE_X ? 34 : 0)//底部iPhoneX的适配高度
#define kNavgationH (IS_IPHONE_X ? 88 : 64)//顶部导航栏高度

// 5.屏幕适配
#define kWidth(R) (R)*(KScreenW)/375.0
#define kHeight(R) kWidth(R)

// 6.字体适配
#define font(R) (R)*(KScreenW)/375.0

// 7.全局颜色
#define XYRMainColor YTHColor(254,48,131)//主色调
//可以添加其他常用颜色,方便修改

// 8.解决日志打印不全的问题
#ifdef DEBUG
#define NSLog( s, ... ) printf("class: <%p %s:(%d) > method: %s \n%s\n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(s), ##__VA_ARGS__] UTF8String] );
#else
#define NSLog( s, ... )
#endif

// 9.获取app的info.plist详细信息
#define Version [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]  //build 版本号
#define ShortVersion [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]; //version 版本号
#define Package [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleIdentifier"] //包名

#define DisplayName [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"] //应用显示的名称
#define BundleName [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"] //工程名

相关文章

  • iOS 开发汇总

    iOS 开发工具 [toc] 文件解释说明 YXCToolHeader 宏定义,头文件导入YXCLog 输出格式自...

  • iOS开发 我的宏定义文件

    刚找了一份新工作,分享一份我在老东家椰视用了2年的宏定义文件吧,中间修改过很多次,就目前而言,我觉得还算比较成熟吧...

  • iOS开发实用技巧之变量的定义:const、static、ext

    参考文章:iOS 不要用宏来定义你的常量iOS开发实用技巧—const、static、extern简介iOS开发笔...

  • IOS NSLog宏定义

    IOS NSLog宏定义 标签(空格分隔): IOS IOS NSLog宏定义 宏定义NSLog方法,不用加";"...

  • iOS 常用宏定义

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

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

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

  • 关于extern引出的问题

    问题 项目中在.mm文件中使用宏: 报错: 解析 iOS的常量声明与定义 iOS中声明常量 定义常量 这个是iOS...

  • iOS常用宏定义

    该文章记录iOS开发中常见的宏定义 识别系统版本

  • iOS之宏定义

    iOS开发小技巧之--WeakSelf宏的进化 宏定义不是C语句,也无须使用分号结束 宏定义并不是变量,它甚至不是...

  • ios开发 -宏定义

    宏定义在很多方面都会使用,例如定义高度、判断iOS系统、工具类,还有诸如文件路径、服务端api接口文档。 ...

网友评论

    本文标题:iOS开发 我的宏定义文件

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