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)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM