iOS 開發常用宏定義

#define SharedAppDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)
#define StandardUserDefaults [NSUserDefaults standardUserDefaults]

//過期
#define DEPRECATED(_version) __attribute__((deprecated))

//singleton
#define SYNTHESIZE_SINGLETON_FOR_HEADER(className) \
\
+ (className *) sharedInstance;

#define SYNTHESIZE_SINGLETON_FOR_CLASS(className) \
\
+ (className *)sharedInstance { \
static className *sharedInstance = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
sharedInstance = [[self alloc] init]; \
}); \
return sharedInstance; \
}

/////////////////////////////////////////// device ////////////////////////////////////////////
//判斷是否是Retina顯示屏
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
//判斷是否是iPhone5
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define isInch4 [UIScreen mainScreen].bounds.size.height==568
//判斷是否是pad
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
//主屏寬
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
//主屏高
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
//當前設備的ios版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
//當前設備的語言
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

/////////////////////////////////////////// color ////////////////////////////////////////////
//RGB Color macro
#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]

//RGB color macro with alpha
#define UIColorFromRGBWithAlpha(rgbValue,a) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]

#endif

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章