宏定义
简介:
<ol start="1" class="dp-objc" style="padding:0px; border:none; list-style-position:initial; color:rgb(92,92,92); font-family:Consolas,'Courier New',Courier,mono,serif; line-height:26px; margin:0px
-
- #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]]
-
-
- #define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]
-
-
- #define ImageNamed(_pointer) [UIImage imageNamed:_pointer]
-
-
-
-
-
- #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]
-
-
- #define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]
-
-
- #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)]
-
-
-
-
-
-
- #define VIEWWITHTAG(_OBJECT, _TAG) [_OBJECT viewWithTag : _TAG]
-
-
-
-
-
-
- #define DEFINE_SINGLETON_FOR_HEADER(className) \
- \
- + (className *)shared##className;
-
-
- #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