美文网首页
iOS 那些你可能会用到的宏定义

iOS 那些你可能会用到的宏定义

作者: 隔墙送来秋千影 | 来源:发表于2018-05-17 17:07 被阅读55次
#define SCREEN_WIDTH          [UIScreen mainScreen].bounds.size.width
#define SCREEN_HEIGHT         [UIScreen mainScreen].bounds.size.height
#define SCREEN_SIZE           [UIScreen mainScreen].bounds.size
#define SCALE_WIDTH           SCREEN_WIDTH/375
#define STATUSBAR_HEIGHT      [[UIApplication sharedApplication] statusBarFrame].size.height
#define NAVIGATIONBAR_HEIGHT  self.navigationController.navigationBar.height
#define KISIPHONEX            ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)

#define RGBColor(r,g,b)       [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define RGBAColor(r,g,b,a)    [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:a]
#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 kFontSize(size)       [UIFont systemFontOfSize:size]

//弱 强引用
#define kWeakSelf(type)        __weak typeof(type) weak##type = type;
#define kStrongSelf(type)      __strong typeof(type) type = weak##type;

#define kGetImage(imageName)  [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]

#define UUIDSTRING            [[UIDevice currentDevice].identifierForVendor UUIDString]
#define VERSION               [[UIDevice currentDevice].systemVersion floatValue]
#define kApplication          [UIApplication sharedApplication]
#define kKeyWindow            [UIApplication sharedApplication].keyWindow
#define kAppDelegate          [UIApplication sharedApplication].delegate
#define kUserDefaults         [NSUserDefaults standardUserDefaults]
#define kNotificationCenter   [NSNotificationCenter defaultCenter]
#define kAppVersion           [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//GCD  一次性执行
#define kDISPATCH_ONCE_BLOCK(onceBlock) static                         
dispatch_once_t onceToken; dispatch_once(&onceToken, onceBlock)
//GCD  Main线程上运行
#define kDISPATCH_MAIN_THREAD(mainQueueBlock)                            
dispatch_async(dispatch_get_main_queue(), mainQueueBlock)
//GCD 开启异步线程
#define kDISPATCH_GLOBAL_QUEUE_DEFAULT(globalQueueBlock)  
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), globalQueueBlocl)

相关文章

网友评论

      本文标题:iOS 那些你可能会用到的宏定义

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