iOS --- 总结Objective-C中常用的宏定义(持续更新中)
2015-12-20 19:37
573 查看
将iOS开发中常用的宏定义整理如下,仅包含Objective-C。
而对于Swift,不能使用宏,则可以定义全局函数或者extension。请参考博客iOS — 总结Swift中常用的全局函数和extension(持续更新中)。
而对于Swift,不能使用宏,则可以定义全局函数或者extension。请参考博客iOS — 总结Swift中常用的全局函数和extension(持续更新中)。
// // Macro.h // // Objective-C useful macro for Chris Hu // // App #define APP_VERSION [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] // System Version #define SYSTEM_VERSION ([[[UIDevice currentDevice] systemVersion] floatValue]) #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame) #define SYSTEM_VERSION_HIGHER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending) #define SYSTEM_VERSION_EQUAL_TO_OR_HIGHER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) #define SYSTEM_VERSION_LOWER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending) #define SYSTEM_VERSION_EQUAL_TO_OR_LOWER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending) // Color #define RGB(r,g,b) [UIColor colorWithRed:r / 255.f green:g / 255.f blue:b / 255.f alpha:1.f] #define RGBA(r,g,b,a) [UIColor colorWithRed:r / 255.f green:g / 255.f blue:b / 255.f alpha:a] #define RGB_HEX(hex) RGBA((float)((hex & 0xFF0000) >> 16),(float)((hex & 0xFF00) >> 8),(float)(hex & 0xFF),1.f) #define RGBA_HEX(hex,a) RGBA((float)((hex & 0xFF0000) >> 16),(float)((hex & 0xFF00) >> 8),(float)(hex & 0xFF),a) #define COLOR_LIGHT_BLUE RGB_HEX(0x7f8b97) #define COLOR_DEEP_BLUE RGB_HEX(0x00b3d6) // Language #define CURRENT_LANGUAGE ([[NSLocale preferredLanguages] objectAtIndex:0]) #define IS_LANGUAGE(l) [CURRENT_LANGUAGE hasPrefix:l] #define IS_LANGUAGE_EN IS_LANGUAGE(@"en") // Font #define FONT_SOFIA_MEDIUM(s) [UIFont fontWithName:@"SofiaProSoft-Medium" size:s] #define FONT_SOFIA_SOFT(s) [UIFont fontWithName:@"SofiaProSoft" size:s] // Screen #define SCREEN_SIZE [[UIScreen mainScreen] bounds].size #define SCREEN_WIDTH [[UIScreen mainScreen] bounds].size.width #define SCREEN_HEIGHT [[UIScreen mainScreen] bounds].size.height // GCD #define GCD_GLOBAL(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block) #define GCD_MAIN(block) dispatch_async(dispatch_get_main_queue(), block)
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- C/C++ 宏详细解析
- 深入探讨:宏、内联函数与普通函数的区别
- C++十六进制宏的用法详解
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 浅析iOS应用开发中线程间的通信与线程安全问题
- 检测iOS设备是否越狱的方法
- C++基础入门教程(二):数据、变量、宏等
- 枚举和宏的区别详细解析
- Objective-C的内省(Introspection)用法小结
- .net平台推送ios消息的实现方法
- 浅析c++ 宏 #val 在unicode下的使用