iOS常用define宏定义

1. 屏幕宽高及常用尺寸

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

#define NavigationBar_HEIGHT 44.0f
#define TabBar_HEIGHT 49.0f
#define StatusBar_HEIGHT 20.0f
#define ToolsBar_HEIGHT 44.0f

2. 颜色转换

//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]

//带有RGBA的颜色设置
#define RGBA(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
#define RGB(r,g,b) RGBA(r,g,b,1.0f)

3. 通知

#define POST_NOTIFY(__NAME, __OBJ, __INFO) [[NSNotificationCenter defaultCenter] postNotificationName:__NAME object:__OBJ userInfo:__INFO];

#define LISTEN_NOTIFY(__NAME, __OBSERVER, __SELECTOR) [[NSNotificationCenter defaultCenter] addObserver:__OBSERVER selector:__SELECTOR name:__NAME object:nil];

#define REMOVE_NOTIFY(__OBSERVER) [[NSNotificationCenter defaultCenter] removeObserver:__OBSERVER];

4. 系统版本

#define iOS8 [[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 ? 1 : 0

5. 带参数的URL

#define URL(__TYPE, __RECORD_ID, __MSG_ID) [NSString stringWithFormat:@"http://192.1.1.1:8000/?type=%ld&record_id=%ld&msg_id=%ld",__TYPE,__RECORD_ID,__MSG_ID]

上一篇:系列三VisualSvn Server


下一篇:总线接口与计算机通信(三)UART起止式异步通用串行数据总线