宏定义,是开发过程中提高效率的有效工具。很有必要归纳一些全局通用的宏定义,以便简单高效的使用。
如下,整理了一些通用宏定义,应该是开发必备的:
#ifndef Medical_Wisdom_UConstants_h
#define Medical_Wisdom_UConstants_h
/******************************************************/
/**** debug log **/ //NSLog输出信息
#ifdef DEBUG
#define DLog( s, ... ) NSLog( @"< %@:(%d) > %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define DLog( s, ... )
#endif
/*** DEBUG RELEASE */
#if DEBUG
#define MCRelease(x)
#else
#define MCRelease(x)
#endif
/***** release *****/
#define NILRelease [x release], x = nil
#pragma mark - Frame(宏 x,y,width,height)
#define MainScreenScale [[UIScreen mainScreen]scale] //屏幕的分辨率 当结果为1时,显示的是普通屏幕,结果为2时,显示的是Retian屏幕
// App Frame Height&Width
#define Application_Frame [[UIScreen mainScreen] applicationFrame] //除去信号区的屏幕的frame
#define APP_Frame_Height [[UIScreen mainScreen] applicationFrame].size.height //应用程序的屏幕高度
#define App_Frame_Width [[UIScreen mainScreen] applicationFrame].size.width //应用程序的屏幕宽度
/*** MainScreen Height Width */
#define kScreenHeight [[UIScreen mainScreen] bounds].size.height //主屏幕的高度
#define kScreenWidth [[UIScreen mainScreen] bounds].size.width //主屏幕的宽度
//找 window
#define GHKeyWindow [UIApplication sharedApplication].keyWindow
// 当iOS前系统版本
#define kDevice_CurrentDevice [[[UIDevice currentDevice] systemVersion] floatValue]
// View 坐标(x,y)和宽高(width,height)
#define X(v) (v).frame.origin.x
#define Y(v) (v).frame.origin.y
#define WIDTH(v) (v).frame.size.width
#define HEIGHT(v) (v).frame.size.height
#define MinX(v) CGRectGetMinX((v).frame) // 获得控件屏幕的x坐标
#define MinY(v) CGRectGetMinY((v).frame) // 获得控件屏幕的Y坐标
#define MidX(v) CGRectGetMidX((v).frame) //横坐标加上到控件中点坐标
#define MidY(v) CGRectGetMidY((v).frame) //纵坐标加上到控件中点坐标
#define MaxX(v) CGRectGetMaxX((v).frame) //横坐标加上控件的宽度
#define MaxY(v) CGRectGetMaxY((v).frame) //纵坐标加上控件的高度
#define CONTRLOS_FRAME(x,y,width,height) CGRectMake(x,y,width,height)
// 系统控件的默认高度
#define kStatusBarHeight (20.f)
#define kTopBarHeight (44.f)
#define kBottomBarHeight (49.f)
#define kCellDefaultHeight (44.f)
// 当控件为全屏时的横纵左边
#define kFrameX (0.0)
#define kFrameY (0.0)
#define kPhoneFrameWidth (320.0)
#define kPhoneWithStatusNoPhone5Height (480.0)
#define kPhoneNoWithStatusNoPhone5Height (460.0)
#define kPhoneWithStatusPhone5Height (568.0)
#define kPhoneNoWithStatusPhone5Height (548.0)
#define kPadFrameWidth (768.0)
#define kPadWithStatusHeight (1024.0)
#define kPadNoWithStatusHeight (1004.0)
#define DesignHeight 1334.0
#define DesignWidth 750.0
#define GetWidth(width) (width)/DesignWidth*kScreenWidth
//判断是不是4s如果是则高度和5s一样的比例
#define GetHeight(height) (kScreenHeight > 568 ? (height)/DesignHeight*kScreenHeight : (height)/DesignHeight*568)
//中英状态下键盘的高度
#define kEnglishKeyboardHeight (216.f)
#define kChineseKeyboardHeight (252.f)
#pragma mark - Funtion Method (宏 方法)
//PNG JPG 图片路径
#define PNGPATH(NAME) [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:NAME] ofType:@"png"]
#define JPGPATH(NAME) [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:NAME] ofType:@"jpg"]
#define PATH(NAME,EXT) [[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)]
//加载图片
#define PNGIMAGE(NAME) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:@"png"]]
#define JPGIMAGE(NAME) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:@"jpg"]]
#define IMAGE(NAME,EXT) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)]]
#define IMAGENAMED(NAME) [UIImage imageNamed:NAME]
// 角度和弧度转换
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)
//字体大小(常规/粗体)
#define BOLDSYSTEMFONT(FONTSIZE) [UIFont boldSystemFontOfSize:FONTSIZE]
#define SYSTEMFONT(FONTSIZE) [UIFont systemFontOfSize:FONTSIZE]
#define FONT(NAME,FONTSIZE) [UIFont fontWithName:(NAME) size:(FONTSIZE)]
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
//当前版本
#define FSystenVersion ([[[UIDevice currentDevice] systemVersion] floatValue])
#define DSystenVersion ([[[UIDevice currentDevice] systemVersion] doubleValue])
#define SSystemVersion ([[UIDevice currentDevice] systemVersion])
//当前语言
#define CURRENTLANGUAGE ([[NSLocale preferredLanguages] objectAtIndex:0])
//是否Retina屏
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) :NO)
//是否iPhone5
#define ISIPHONE [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone
#define ISIPHONE5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
//是否是iPad
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// UIView - viewWithTag 通过tag值获得子视图
#define VIEWWITHTAG(_OBJECT,_TAG) [_OBJECT viewWithTag : _TAG]
//应用程序的名字
#define AppDisplayName [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]
//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]
//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)
//NSUSerDefault
#define USER_DEFAULT [NSUserDefaults standardUserDefaults]
//判断设备室真机还是模拟器
#if TARGET_OS_IPHONE
/** iPhone Device */
#endif
#if TARGET_IPHONE_SIMULATOR
/** iPhone Simulator */
#endif
#endif
网友评论