您的位置:首页 > 移动开发 > IOS开发

iOS常用宏定义

2016-01-29 12:16 375 查看
1.首次启动判断:

#define First_Launched @"firstLaunch"
2.ios7系统判断:

#define IsIOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >=7.0 ? YES : NO)
3.判断是否Retina屏、是否IPhone5、是否IPad
#define isRetina ([UIScreen instancesRespondToSelector:
@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960),
[[UIScreen mainScreen] currentMode].size) : NO)

#define iPhone5 ([UIScreen instancesRespondToSelector:
@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136),
[[UIScreen mainScreen] currentMode].size) : NO)
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

4.加载图片宏:

#define LOADIMAGE(file,type) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:type]]

5.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]
6.设置颜色RGB
#define COLOR(R, G, B, A)
[UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]

7.去除"-(id)performSelector:(SEL)aSelector withObject:(id)object;"的警告
#define SuppressPerformSelectorLeakWarning(Stuff) \
do { \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Warc-performSelector-leaks\"")
\
Stuff; \
_Pragma("clang diagnostic pop") \
} while (0)

2.定义沙盒目录文件的宏

?
3.工具类的宏

?
4.通知Notification相关的宏

?
服务端API接口的宏

?
还有很多其他类型的宏,此处不一一列举

创建一个import所有宏相关的文件Macros.h

?
在xcode项目的pch文件中,导入Macros.h文件

?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: