宏定义在C系开发中可以说占有举足轻重的作用。使用宏定义的好处是不言自明的,在节省工作量的同时,代码可读性大大增加。
#pragma mark -尺寸设置
///屏幕宽度
#define Screen_width ([UIScreen mainScreen].bounds.size.width)
///屏幕高度
#define Screen_height ([UIScreen mainScreen].bounds.size.height)
#define TabbarHeight 49
#define SearchBarHeight 45
#define StatusBarHeight 20
#define NavigationHeight 44
#pragma mark -对象管理
///当前app delegate
#define APPDelegate ((AppDelegate *)[UIApplication sharedApplication].delegate)
///内存管理 释放对象
#define Safe_release(x) {if (x){[x release];x = nil;}}
/// block self
#define SelfWeak __weak typeof(self) weakSelf = self
#define SelfStrong __strong __typeof__(self) strongSelf = weakSelf
#pragma mark -系统信息
///当前版本号
#define GetCurrentVersion ([[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"])
/// iOS系统版本
#define iOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
/// IOS6的系统
#define ISIOS6 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 6.0)
/// IOS7的系统
#define ISIOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
/// IOS8的系统
#define ISIOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
///系统版本号
#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
///当前系统语言
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
///是否高清屏
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
///是否iPhone5
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
///是否iPad
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#pragma mark - 其他
/// 调试模式下打印信息
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
#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
#define USER_Default [NSUserDefaults standardUserDefaults]
/// G-C-D
#define GCDBackBlock(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define GCDMainBlock(block) dispatch_async(dispatch_get_main_queue(),block)
#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 UIColorRGB(R,G,B) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:1.0]
///设置颜色 示例:UIColorHex(0x26A7E8)
#define UIColorHex(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]
///设置颜色与透明度 示例:UIColorHEX_Alpha(0x26A7E8, 0.5)
#define UIColorHex_Alpha(rgbValue, al) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:al]
#pragma mark - 系统功能
#define MailSend(email) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"mailto://%@",email]])
#define PhoneCall(phone) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",phone]])
#define PhoneCallAuto(phone) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@",phone]])
#define SMSSend(phone) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"sms://%@",phone]])
#define SafariOpen(url) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:url])