常用宏

来源:互联网 发布:js json 数组 编辑:程序博客网 时间:2024/06/05 23:44
#define LOGOPEN 1
009#define VC_LOGOPEN 1
010#define DB_BLOCK_LOG
011#define NET_BLOCK_LOG 1
012 
013 
014#pragma mark ---log  flag
015 
016#define LogFrame(frame) NSLog(@"frame[X=%.1f,Y=%.1f,W=%.1f,H=%.1f",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height)
017#define LogPoint(point) NSLog(@"Point[X=%.1f,Y=%.1f]",point.x,point.y)
018 
019#if LOGOPEN
020    #define DDDLog(FORMAT, ...) fprintf(stderr,"%s:%d\t%s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
021#else
022    #define DDDLog(FORMAT, ...)
023#endif
024 
025//viewController log
026#ifdef VC_LOGOPEN
027#define LogVC DDDLog
028#else
029#define LogVC
030#endif
031 
032//dbbase log
033#ifdef DB_BLOCK_LOG
034    #define LogDB DDDLog
035#else
036    #define LogDB
037#endif
038 
039 
040//networking log
041#if NET_BLOCK_LOG
042    #define LogNET DDDLog
043#else
044    #define LogNET
045#endif
046 
047//view log
048#ifdef VIEW_BLOCK_LOG
049    #define LogVIEW DDDLog
050#else
051    #define LogVIEW
052#endif
053 
054 
055#pragma mark --time setup
056 
057 
058#if TARGET_IPHONE_SIMULATOR
059    #import <objc/objc-runtime.h>
060#else
061    #import <objc/runtime.h>
062#endif
063 
064#ifdef  _DEBUG
065    #define DNSLog(...);    NSLog(__VA_ARGS__);
066    #define DNSLogMethod    NSLog(@"[%s] %@", class_getName([self class]), NSStringFromSelector(_cmd));
067    #define DNSLogPoint(p)  NSLog(@"%f,%f", p.x, p.y);
068    #define DNSLogSize(p)   NSLog(@"%f,%f", p.width, p.height);
069    #define DNSLogRect(p)   NSLog(@"%f,%f %f,%f", p.origin.x, p.origin.y, p.size.width, p.size.height);
070 
071    CFAbsoluteTime startTime;
072    #define D_START         startTime=CFAbsoluteTimeGetCurrent();
073    #define D_END           DNSLog(@"[%s] %@ %f seconds", class_getName([self class]), NSStringFromSelector(_cmd), CFAbsoluteTimeGetCurrent() - startTime );
074#else
075    #define DNSLog(...);    // NSLog(__VA_ARGS__);
076    #define DNSLogMethod    // NSLog(@"[%s] %@", class_getName([self class]), NSStringFromSelector(_cmd) );
077    #define DNSLogPoint(p)  // NSLog(@"%f,%f", p.x, p.y);
078    #define DNSLogSize(p)   // NSLog(@"%f,%f", p.width, p.height);
079    #define DNSLogRect(p)   // NSLog(@"%f,%f %f,%f", p.origin.x, p.origin.y, p.size.width, p.size.height);
080 
081    #define D_START         // CFAbsoluteTime startTime=CFAbsoluteTimeGetCurrent();
082    #define D_END           // DNSLog(@"New %f seconds", CFAbsoluteTimeGetCurrent() - startTime );
083#endif
084 
085#define SAFE_FREE(p) { if(p) { free(p); (p)=NULL; } }
086 
087#pragma mark ---- AppDelegate
088//AppDelegate
089#define APPDELEGATE [(AppDelegate*)[UIApplication sharedApplication]  delegate]
090//UIApplication
091#define APPD  [UIApplication sharedApplication]
092#define rootNavVC (UINavigationController*)[[[[UIApplication sharedApplication] delegate] window] rootViewController]
093 
094#define isPad  ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
095#define isiPhone5 ([[UIScreen mainScreen]bounds].size.height == 568)
096 
097 
098 
099#pragma mark ---- String  functions
100#define EMPTY_STRING        @""
101#define STR(key)            NSLocalizedString(key, nil)
102 
103 
104#pragma mark ---- UIImage  UIImageView  functions
105#define IMG(name) [UIImage imageNamed:name]
106#define IMGF(name) [UIImage imageNamedFixed:name]
107 
108#pragma mark ---- File  functions
109#define PATH_OF_APP_HOME    NSHomeDirectory()
110#define PATH_OF_TEMP        NSTemporaryDirectory()
111#define PATH_OF_DOCUMENT    [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
112 
113 
114#pragma mark ---- color functions
115#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
116#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
117 
118#pragma mark ----Size ,X,Y, View ,Frame
119//get the  size of the Screen
120#define SCREEN_HEIGHT [[UIScreen mainScreen]bounds].size.height
121#define SCREEN_WIDTH [[UIScreen mainScreen]bounds].size.width
122#define HEIGHT_SCALE  ([[UIScreen mainScreen]bounds].size.height/480.0)
123 
124//get the  size of the Application
125#define APP_HEIGHT [[UIScreen mainScreen]applicationFrame].size.height
126#define APP_WIDTH [[UIScreen mainScreen]applicationFrame].size.width
127 
128#define APP_SCALE_H  ([[UIScreen mainScreen]applicationFrame].size.height/480.0)
129#define APP_SCALE_W  ([[UIScreen mainScreen]applicationFrame].size.width/320.0)
130 
131//get the left top origin's x,y of a view
132#define VIEW_TX(view) (view.frame.origin.x)
133#define VIEW_TY(view) (view.frame.origin.y)
134 
135//get the width size of the view:width,height
136#define VIEW_W(view)  (view.frame.size.width)
137#define VIEW_H(view)  (view.frame.size.height)
138 
139//get the right bottom origin's x,y of a view
140#define VIEW_BX(view) (view.frame.origin.x + view.frame.size.width)
141#define VIEW_BY(view) (view.frame.origin.y + view.frame.size.height )
142 
143//get the x,y of the frame
144#define FRAME_TX(frame)  (frame.origin.x)
145#define FRAME_TY(frame)  (frame.origin.y)
146//get the size of the frame
147#define FRAME_W(frame)  (frame.size.width)
148#define FRAME_H(frame)  (frame.size.height)
149 
150#define DistanceFloat(PointA,PointB) sqrtf((PointA.x - PointB.x) * (PointA.x - PointB.x) + (PointA.y - PointB.y) * (PointA.y - PointB.y))
原创粉丝点击