天天看點

iOS開發筆記之常用宏定義

// 單例
#define SINGLETON_FOR_CLASS(classname) \

\

+ (classname*) shareInstance \

{ \

static dispatch_once_t pred = 0; \

__strong static classname* _sharedObject = nil; \

dispatch_once(&pred, ^{ \

_sharedObject = [[self alloc] init]; \

}); \

return _sharedObject;\

}
           
// 16進制顔色轉為RGB
#define UIColorFromHex(hexColor) [UIColor colorWithRed:(((hexColor & 0xFF0000) >> 16 )) / 255.0 green:((( hexColor & 0xFF00 ) >> 8 )) / 255.0 blue:(( hexColor & 0xFF )) / 255.0 alpha:1.0]
           
#define StatusBar_Height [UIApplication sharedApplication].statusBarFrame.size.height  // 狀态欄高度
#define NaviBar_Height self.navigationController.navigationBar.frame.size.height  // 導航欄高度
           
#define Screen_Width MIN([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)  // 螢幕寬度
#define Screen_Height MAX([UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)  // 螢幕高度