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)  // 屏幕高度

發佈了39 篇原創文章 · 獲贊 3 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章