IOS 程序员开发最常用宏定义

网上对IOS的宏定义比较多,我总结了一些最常用的宏,后续还会继续补上。

 

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)

原文地址:https://www.cnblogs.com/ios8/p/ios-hong.html