iOS常用宏定义大全

iOS常用宏定义大全

2023年7月14日发(作者:)

iOS常⽤宏定义⼤全// Frame#define SCREEN_FRAME ([UIScreen mainScreen].applicationFrame)// 宽度#define SCREEN_WIDTH ([UIScreen mainScreen].)// ⾼度#define SCREEN_HEIGHT ([UIScreen mainScreen].)// iPhone6宽⽐#define KBaseW [UIScreen mainScreen]. / 375// iPhone6⾼⽐#define KBaseH [UIScreen mainScreen]. / 667// RGBA#define RGBA(R /*红*/, G /*绿*/, B /*蓝*/, A /*透明*/) [UIColor colorWithRed: (float)R / 255.f green: (float)G / 255.f blue: (float)B / 255.f alpha: A]// RGB#define RGB(r, g, b) [UIColor colorWithRed: (r) / 255.0 green: (g) / 255.0 blue: (b) / 255.0 alpha: 1.0]// 沙盒⽬录#define kUserDefaults [NSUserDefaults standardUserDefaults]// 获取通知中⼼#define kNotificationCenter [NSNotificationCenter defaultCenter]// 设置随机颜⾊#define kRandomColor [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1// clear背景颜⾊#define kClearColor [UIColor clearColor]// ⾃定义⾼效率的 NSLog#ifdef DEBUG #define kLog(...) NSLog(@"%s 第%d⾏ n %@nn", __func__, __LINE__, [NSString stringWithFormat:__VA_ARGS__])#else #define kLog(...)#endif// 弱引⽤/强引⽤#define kWeakSelf(type) __weak typeof(type) weak##type = type;#define kStrongSelf(type) __strong typeof(type) type = weak##type;// 设置 view 圆⾓和边框#define kViewBorderRadius(View, Radius, Width, Color) [ setCornerRadius: (Radius)]; [ setMasksToBounds:YES]; [ setBorderWidth:(Width)]; [ setBorderColor:[Color CGColor]]// 由⾓度转换弧度 由弧度转换⾓度#define kDegreesToRadian(x) (M_PI * (x) / 180.0)#define kRadianToDegrees(radian) (radian * 180.0) / (M_PI)// 获取keyWindow#define kWindow [UIApplication sharedApplication].keyWindow// 设置状态条加载#define kShowNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = YES// 收起状态条加载#define kHideNetworkActivityIndicator() [UIApplication sharedApplication].networkActivityIndicatorVisible = NO// MBProgressHUD加载#define kShowHUDAndActivity kBackView; [MBProgressHUD showHUDAddedTo:kWindow animated:YES]; kShowNetworkActivityIndicator()// MBProgressHUD隐藏#define kHiddenHUD [MBProgressHUD hideAllHUDsForView:kWindow animated:YES]; kHideNetworkActivityIndicator()// 获取图⽚资源#define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@", imageName]]// 获取当前语⾔#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])// 使⽤ ARC 和 MRC#if __has_feature(objc_arc) // ARC#else // MRC#endif// 判断是否为iPhone#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)// 判断是否为iPad#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)// 判断是否为ipod#define IS_IPOD ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])// 判断是否为 iPhone 5/5s/SE#define iPhone5SE [[UIScreen mainScreen] bounds]. == 320.0f && [[UIScreen mainScreen] bounds]. == 568.0f// 判断是否为iPhone 6/6s#define iPhone6_6s [[UIScreen mainScreen] bounds]. == 375.0f && [[UIScreen mainScreen] bounds]. == 667.0f// 判断是否为iPhone 6Plus/6sPlus#define iPhone6Plus_6sPlus [[UIScreen mainScreen] bounds]. == 414.0f && [[UIScreen mainScreen] bounds]. == 736.0f// 获取系统版本#define IOS_SYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]// 判断 iOS 8 或更⾼的系统版本#define IOS_VERSION_8_OR_LATER (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) ? (YES) : (NO))// 判断是真机还是模拟器#if TARGET_OS_IPHONE // iPhone Device#endif#if TARGET_IPHONE_SIMULATOR // iPhone Simulator#endif// 沙盒⽬录⽂件// 获取temp#define kPathTemp NSTemporaryDirectory()// 获取沙盒 Document#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]// 获取沙盒 Cache#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]// GCD 的宏定义// 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), globa没有⼀蹴⽽就的天才,只有不断点亮天赋的勤者

发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1689265680a226477.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信