ios开发常用的宏
来源:互联网 发布:贝叶斯分类算法 编辑:程序博客网 时间:2024/05/16 14:08
转载自 http://www.cocoachina.com/bbs/read.php?tid=137317&page=1
//use stringmake for NSString#define StringMake(fmt, ...) [NSString stringWithFormat:(@"%s [Line %d] " fmt),__PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__]
#define NavigationBar_HEIGHT 44 #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)#define SAFE_RELEASE(x) [x release];x=nil#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion]) #define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0] //use dlog to print while in debug model#ifdef DEBUG# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);#else# define DLog(...)#endif #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #if TARGET_OS_IPHONE//iPhone Device#endif #if TARGET_IPHONE_SIMULATOR//iPhone Simulator#endif //ARC#if __has_feature(objc_arc) //compiling with ARC#else // compiling without ARC#endif //G-C-D#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block) #define USER_DEFAULT [NSUserDefaults standardUserDefaults]#define ImageNamed(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer]] #pragma mark - common functions #define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; } #pragma mark - degrees/radian functions #define degreesToRadian(x) (M_PI * (x) / 180.0)#define radianToDegrees(radian) (radian*180.0)/(M_PI) #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 ITTDEBUG#define ITTLOGLEVEL_INFO 10#define ITTLOGLEVEL_WARNING 3#define ITTLOGLEVEL_ERROR 1 #ifndef ITTMAXLOGLEVEL #ifdef DEBUG #define ITTMAXLOGLEVEL ITTLOGLEVEL_INFO#else #define ITTMAXLOGLEVEL ITTLOGLEVEL_ERROR#endif #endif // The general purpose logger. This ignores logging levels.#ifdef ITTDEBUG #define ITTDPRINT(xx, ...) NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)#else #define ITTDPRINT(xx, ...) ((void)0)#endif // Prints the current method's name.#define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s", __PRETTY_FUNCTION__) // Log-level based logging macros.#if ITTLOGLEVEL_ERROR <= ITTMAXLOGLEVEL #define ITTDERROR(xx, ...) ITTDPRINT(xx, ##__VA_ARGS__)#else #define ITTDERROR(xx, ...) ((void)0)#endif #if ITTLOGLEVEL_WARNING <= ITTMAXLOGLEVEL #define ITTDWARNING(xx, ...) ITTDPRINT(xx, ##__VA_ARGS__)#else #define ITTDWARNING(xx, ...) ((void)0)#endif #if ITTLOGLEVEL_INFO <= ITTMAXLOGLEVEL #define ITTDINFO(xx, ...) ITTDPRINT(xx, ##__VA_ARGS__)#else #define ITTDINFO(xx, ...) ((void)0)#endif #ifdef ITTDEBUG #define ITTDCONDITIONLOG(condition, xx, ...) { if ((condition)) { \ ITTDPRINT(xx, ##__VA_ARGS__); \ } \ } ((void)0)#else #define ITTDCONDITIONLOG(condition, xx, ...) ((void)0)#endif #define ITTAssert(condition, ...) \do { \ if (!(condition)) { \ [[NSAssertionHandler currentHandler] \ handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \ file:[NSString stringWithUTF8String:__FILE__] \ lineNumber:__LINE__ \ description:__VA_ARGS__]; \ } \} while(0) #define _po(o) DLOG(@"%@", (o))#define _pn(o) DLOG(@"%d", (o))#define _pf(o) DLOG(@"%f", (o))#define _ps(o) DLOG(@"CGSize: {%.0f, %.0f}", (o).width, (o).height)#define _pr(o) DLOG(@"NSRect: {{%.0f, %.0f}, {%.0f, %.0f}}", (o).origin.x, (o).origin.x, (o).size.width, (o).size.height) #define DOBJ(obj) DLOG(@"%s: %@", #obj, [(obj) description]) #define MARK NSLog(@"\nMARK: %s, %d", __PRETTY_FUNCTION__, __LINE__)
#ifdef DEBUG//Debug模式//...#else//发布模式//...//屏蔽NSLog#define NSLog(...) {};#endif//------------------------------------Simulator/Device//区分模拟器和真机#if TARGET_OS_IPHONE//iPhone Device#endif#if TARGET_IPHONE_SIMULATOR//iPhone Simulator#endif//------------------------------------ARC/no RAC//ARC#if __has_feature(objc_arc)//compiling with ARC#else// compiling without ARC#endif//Blocktypedef void(^VoidBlock)();typedef BOOL(^BoolBlock)();typedef int (^IntBlock) ();typedef id (^IDBlock) ();typedef void(^VoidBlock_int)(int);typedef BOOL(^BoolBlock_int)(int);typedef int (^IntBlock_int) (int);typedef id (^IDBlock_int) (int);typedef void(^VoidBlock_string)(NSString*);typedef BOOL(^BoolBlock_string)(NSString*);typedef int (^IntBlock_string) (NSString*);typedef id (^IDBlock_string) (NSString*);typedef void(^VoidBlock_id)(id);typedef BOOL(^BoolBlock_id)(id);typedef int (^IntBlock_id) (id);typedef id (^IDBlock_id) (id);//System#define PasteString(string) [[UIPasteboard generalPasteboard] setString:string];#define PasteImage(image) [[UIPasteboard generalPasteboard] setImage:image];//Image//可拉伸的图片#define ResizableImage(name,top,left,bottom,right) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right)]#define ResizableImageWithMode(name,top,left,bottom,right,mode) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right) resizingMode:mode]//file//读取文件的文本内容,默认编码为UTF-8#define FileString(name,ext) [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)] encoding:NSUTF8StringEncoding error:nil]#define FileDictionary(name,ext) [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]]#define FileArray(name,ext) [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]]//数学#define PI 3.14159//输出frame(frame是结构体,没法%@)#define LOGFRAME(f) NSLog(@"\nx:%f\ny:%f\nwidth:%f\nheight:%f\n",f.origin.x,f.origin.y,f.size.width,f.size.height)#define LOGBOOL(b) NSLog(@"%@",b?@"YES":@"NO");//弹出信息#define ALERT(msg) [[[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show]//App#define kApp ((AppDelegate *)[UIApplication sharedApplication].delegate)#define kNav ((AppDelegate *)[UIApplication sharedApplication].delegate.navigationController)//color#define RGB(r, g, b) [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:1.0]#define RGBAlpha(r, g, b, a) [UIColor colorWithRed:((r) / 255.0) green:((g) / 255.0) blue:((b) / 255.0) alpha:(a)]#define HexRGB(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 HexRGBAlpha(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:(a)]//转换#define I2S(number) [NSString stringWithFormat:@"%d",number]#define F2S(number) [NSString stringWithFormat:@"%f",number]#define DATE(stamp) [NSDate dateWithTimeIntervalSince1970:[stamp intValue]];//设备屏幕尺寸#define kScreen_Height ([UIScreen mainScreen].bounds.size.height)#define kScreen_Width ([UIScreen mainScreen].bounds.size.width)#define kScreen_Frame (CGRectMake(0, 0 ,kScreen_Width,kScreen_Height))#define kScreen_CenterX kScreen_Width/2#define kScreen_CenterY kScreen_Height/2//应用尺寸(不包括状态栏,通话时状态栏高度不是20,所以需要知道具体尺寸)#define kContent_Height ([UIScreen mainScreen].applicationFrame.size.height)#define kContent_Width ([UIScreen mainScreen].applicationFrame.size.width)#define kContent_Frame (CGRectMake(0, 0 ,kContent_Width,kContent_Height))#define kContent_CenterX kContent_Width/2#define kContent_CenterY kContent_Height/2/*类似九宫格的九个点 p1 --- p2 --- p3 | | | p4 --- p5 --- p6 | | | p7 --- p8 --- p9 */#define kP1 CGPointMake(0 ,0)#define kP2 CGPointMake(kContent_Width/2 ,0)#define kP3 CGPointMake(kContent_Width ,0)#define kP4 CGPointMake(0 ,kContent_Height/2)#define kP5 CGPointMake(kContent_Width/2 ,kContent_Height/2)#define kP6 CGPointMake(kContent_Width ,kContent_Height/2)#define kP7 CGPointMake(0 ,kContent_Height)#define kP8 CGPointMake(kContent_Width/2 ,kContent_Height)#define kP9 CGPointMake(kContent_Width ,kContent_Height)//*********************************************//GCD#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)//Device#define isIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]==4)#define isIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]==5)#define isIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]==6)#define isAfterIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]>4)#define isAfterIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]>5)#define isAfterIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]>6)#define iOS ([[[UIDevice currentDevice] systemVersion] floatValue])#define isRetina ([[UIScreen mainScreen] scale]==2)#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)//拨打电话#define canTel ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:"]])#define tel(phoneNumber) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNumber]]])#define telprompt(phoneNumber) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",phoneNumber]]])//打开URL#define canOpenURL(appScheme) ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:appScheme]])#define openURL(appScheme) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:appScheme]])
0 0
- iOS开发常用的宏
- ios开发常用的宏
- iOS开发常用的宏
- iOS开发常用的宏
- iOS开发常用的宏
- ios开发常用的宏
- ios开发常用的宏
- ios开发常用的宏
- ios开发常用的宏
- ios开发常用的宏
- ios开发常用的宏
- iOS开发常用的宏
- iOS开发-常用的宏
- iOS开发常用的宏
- iOS开发常用的宏
- iOS开发常用的宏
- iOS开发常用宏
- iOS开发常用宏
- OPC接口在PI实时数据库中的应用
- C#-Emgu.CV-------视频截取和图像处理基础
- C#-opencv-------显示图片异常"Emgu.CV.CvInvoke"的类型初始值设
- Win8.1春季更新前期编译版本截图遭泄露
- 定制应用程序外观
- ios开发常用的宏
- error while loading shared libraries: xxx.so.x"错误的原因和解决办法
- 一切成功源于积累——20140109 镑美实盘(1)
- 创建常量、原子性的值类型
- [数学]矩阵总结
- android.app.Fragment$InstantiationException:(小结)
- Timer 与 TimerTask
- Ubuntu12.04 更新源
- 设计模式(5) 单例模式(SINGLETON)