首页 > 代码库 > iOS开发常用的宏定义
iOS开发常用的宏定义
#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 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] //背景色
#define SAFE_DELETE(P) if(P) { [P release], P = nil; } //安全删除对象
#define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A] //带rgba的颜色值
#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] //rgb颜色转换(16进制转10进制)
#define CLEARCOLOR [UIColor clearColor] //清除背景色
#define alertContent(content) UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" \
message:content \
delegate:nil \
cancelButtonTitle:@"确定" \
otherButtonTitles:nil]; \
[alert show]; \
//警告框内容提示
#define degreesToRadian(x) (M_PI * (x) / 180.0) //角度转弧度
#define radianToDegrees(radian) (radian*180.0)/(M_PI) //弧度转角度
//以下三个宏是用来判断设备类型的
#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)
iOS开发常用的宏定义