- // 安全釋放
- #define RELEASE_SAFELY(__Pointer) do{[__Pointer release],__Pointer = nil;} while(0)
- // 屏幕的物理高度
- #define ScreenHeight [UIScreen mainScreen].bounds.size.height
- // 屏幕的物理寬度
- #define ScreenWidth [UIScreen mainScreen].bounds.size.width
- // 調試
- #define NSLOG_FUNCTION NSLog(@"%s,%d",__FUNCTION__,__LINE__)
- //----------------------圖片————————————————————————————————————————
- //讀取本地圖片
- #define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]
- //定義UIImage對象
- #define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]
- //定義UIImage對象
- #define ImageNamed(_pointer) [UIImage imageNamed:_pointer]
- //———————————————————————顏色類———————————————————————————-----—————————————
- // 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]
- //帶有RGBA的顏色設置
- #define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]
- // 獲取RGB顏色
- #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
- #define RGB(r,g,b) RGBA(r,g,b,1.0f)
- //背景色
- #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]
- //清除背景色
- #define CLEARCOLOR [UIColor clearColor]
- #pragma mark - color functions
- #define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
- #define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
- //———————————————————————TAG宏———————————————————————————-----—————————————
- //viewWithTag
- #define VIEWWITHTAG(_OBJECT, _TAG) [_OBJECT viewWithTag : _TAG]
- //———————————————————————單例模式宏———————————————————————————-----—————————————
- //.h文件處的聲明
- #define DEFINE_SINGLETON_FOR_HEADER(className) \
- \
- + (className *)shared##className;
- //.m文件處的聲明
- #define DEFINE_SINGLETON_FOR_CLASS(className) \
- \
- + (className *)shared##className { \
- static className *shared##className = nil; \
- static dispatch_once_t onceToken; \
- dispatch_once(&onceToken, ^{ \
- shared##className = [[self alloc] init]; \
- }); \
- return shared##className; \
- }
- //———————————————————————單例模式———————————————————————————-----—————————————
- static DataBaseHandle * handle = nil;
- + (DataBaseHandle *)shareInstance
- {
- @synchronized(self){
- if (!handle) {
- handle = [[DataBaseHandle alloc] init];
- }
- }
- return handle;
- }
- —————————————不用你把所有NSLog的刪除或註釋,直接修改#if 判斷的值就行了(1執行,0不執行)——————————————
- #if 1
- #define NSLog(FORMAT, ...) fprintf(stderr,"[%s:%d行] %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
- #else
- #define NSLog(FORMAT, ...) nil
- #endif
- #define NEED_OUTPUT_LOG 0
- #if NEED_OUTPUT_LOG
- #define SLog(xx, ...) NSLog(xx, ##__VA_ARGS__)
- #define SLLog(xx, ...) NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
- #define SLLogRect(rect) \
- SLLog(@"%s x=%f, y=%f, w=%f, h=%f", #rect, rect.origin.x, rect.origin.y, \
- rect.size.width, rect.size.height)
- #define SLLogPoint(pt) \
- SLLog(@"%s x=%f, y=%f", #pt, pt.x, pt.y)
- #define SLLogSize(size) \
- SLLog(@"%s w=%f, h=%f", #size, size.width, size.height)
- #define SLLogColor(_COLOR) \
- SLLog(@"%s h=%f, s=%f, v=%f", #_COLOR, _COLOR.hue, _COLOR.saturation, _COLOR.value)
- #define SLLogSuperViews(_VIEW) \
- { for (UIView* view = _VIEW; view; view = view.superview) { SLLog(@"%@", view); } }
- #define SLLogSubViews(_VIEW) \
- { for (UIView* view in [_VIEW subviews]) { SLLog(@"%@", view); } }
- #else
- #define SLog(xx, ...) ((void)0)
- #define SLLog(xx, ...) ((void)0)
- #endif
一些常用的宏定義
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.