最近空闲,想着整理一下iOS当中的宏,方便以后用的时候查找,如果小伙伴们有什么好的宏定义,欢迎在下面留言哦!与人方便自己方便嘛😀
#ifdef DEBUG
#define DCLog(...) NSLog(__VA_ARGS__)
#else
#define DCLog(...)
#endif
#define iOS7 ([UIDevice currentDevice].systemVersion.doubleValue >= 7.0)
#define ScreenWidth [UIScreen mainScreen].bounds.size.width
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define WIDTHSCALE6 ScreenWidth/375.0f
#define HEIGHTSCALE6 ScreenHeight/667.0f
//判断是否是iPhone
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
//判断是否是iPad
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define SCREEN_MAX_LENGTH (MAX(ScreenWidth, ScreenHeight))
#define SCREEN_MIN_LENGTH (MIN(ScreenWidth, ScreenHeight))
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5_5S (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6_7_8 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P_7P_8P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
#define ISiPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
#define ISiPhoneXR ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : NO)
#define ISiPhoneXS ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
#define ISiPhoneXS_MAX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) : NO)
//异性全面屏
#define isFullScreen (ISiPhoneX || ISiPhoneXR || ISiPhoneXS || ISiPhoneXS_MAX)
#define navHeight (44.0f)//导航栏高度
#define statusHeight (isFullScreen?44.0f:20.0f)//电池条高度
#define tabbarHeight (isFullScreen?83.0f:49.0f)//tabBar高度
#define bottomSafeHeight (isFullScreen?34.0f:0.0f)
// 去除上下导航栏剩余中间视图高度
#define ContentHeight (ScreenHeight - navHeight - statusHeight- tabbarHeight - bottomSafeHeight)
//颜色
#define DCColor(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
/** rgb颜色转换(16进制->10进制)*/
#define UIColorFromRGB(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]
#define RandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
//黑色字体
#define BlackColor DCColor(60, 60, 60)
#define IMAGENAME(a) [UIImage imageNamed:a]
#define FONT(a) [UIFont systemFontOfSize:a]
#define Str_IsEmpty(str) (((str) == nil) || ([(str) isEqual:[NSNull null]]) || ([@"" isEqualToString:(str)]))
#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
#define NOTIFICATION [NSNotificationCenter defaultCenter]
#define DEFAULT [NSUserDefaults standardUserDefaults]
//获取沙盒 Document
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//获取沙盒 Cache
#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
// app版本号
#define DEVICE_APP_VERSION (NSString *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
// app Build版本号
#define DEVICE_APP_BUILD (NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
// 系统版本号
#define DEVICE_OS_VERSION [UIDevice currentDevice].systemVersion.doubleValue
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
网友评论