iOS开发 我的宏定义文件

2018-02-27 11:13:33来源:https://www.jianshu.com/p/c86fba7f1b5f作者:嫌疑人zx人点击

分享



刚找了一份新工作,分享一份我在老东家椰视用了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)
//手机型号和平板
#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)
// 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)
// 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"] //工程名







最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台