一些常用的宏定义
2015-12-18 10:13
447 查看
// 安全释放 #define RELEASE_SAFELY(__Pointer) do{[__Pointer release],__Pointer = nil;} while(0) // 屏幕的物理高度 #define ScreenHeight [UIScreen mainScreen].bounds.size.height // 屏幕的物理宽度 #define ScreenWidth [UIScreen mainScreen].bounds.size.width // 调试 #define NSLOG_FUNCTION NSLog(@"%s,%d",__FUNCTION__,__LINE__)
//----------------------图片———————————————————————————————————————— //读取本地图片 #define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]] //定义UIImage对象 #define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]] //定义UIImage对象 #define ImageNamed(_pointer) [UIImage imageNamed:_pointer]
//———————————————————————颜色类———————————————————————————-----————————————— // 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 COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A] // 获取RGB颜色 #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) //背景色 #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0] //清除背景色 #define CLEARCOLOR [UIColor clearColor] #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)]
//———————————————————————TAG宏———————————————————————————-----————————————— //viewWithTag #define VIEWWITHTAG(_OBJECT, _TAG) [_OBJECT viewWithTag : _TAG]
//———————————————————————单例模式宏———————————————————————————-----————————————— //.h文件处的声明 #define DEFINE_SINGLETON_FOR_HEADER(className) \ \ + (className *)shared##className; //.m文件处的声明 #define DEFINE_SINGLETON_FOR_CLASS(className) \ \ + (className *)shared##className { \ static className *shared##className = nil; \ static dispatch_once_t onceToken; \ dispatch_once(&onceToken, ^{ \ shared##className = [[self alloc] init]; \ }); \ return shared##className; \ }
//———————————————————————单例模式———————————————————————————-----————————————— static DataBaseHandle * handle = nil; + (DataBaseHandle *)shareInstance { @synchronized(self){ if (!handle) { handle = [[DataBaseHandle alloc] init]; } } return handle; } —————————————不用你把所有NSLog的删除或注释,直接修改#if 判断的值就行了(1执行,0不执行)—————————————— #if 1 #define NSLog(FORMAT, ...) fprintf(stderr,"[%s:%d行] %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]); #else #define NSLog(FORMAT, ...) nil #endif #define NEED_OUTPUT_LOG 0 #if NEED_OUTPUT_LOG #define SLog(xx, ...) NSLog(xx, ##__VA_ARGS__) #define SLLog(xx, ...) NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__) #define SLLogRect(rect) \ SLLog(@"%s x=%f, y=%f, w=%f, h=%f", #rect, rect.origin.x, rect.origin.y, \ rect.size.width, rect.size.height) #define SLLogPoint(pt) \ SLLog(@"%s x=%f, y=%f", #pt, pt.x, pt.y) #define SLLogSize(size) \ SLLog(@"%s w=%f, h=%f", #size, size.width, size.height) #define SLLogColor(_COLOR) \ SLLog(@"%s h=%f, s=%f, v=%f", #_COLOR, _COLOR.hue, _COLOR.saturation, _COLOR.value) #define SLLogSuperViews(_VIEW) \ { for (UIView* view = _VIEW; view; view = view.superview) { SLLog(@"%@", view); } } #define SLLogSubViews(_VIEW) \ { for (UIView* view in [_VIEW subviews]) { SLLog(@"%@", view); } } #else #define SLog(xx, ...) ((void)0) #define SLLog(xx, ...) ((void)0) #endif
相关文章推荐
- 确定数目的自动轮播
- linux下常用FTP命令 1. 连接ftp服务器
- CentOS6.5 系统挂载 NTFS 分区的移动硬盘
- IOS视频分解图片、图片合成视频
- XML<![CDATA[ ]]>嵌套
- LINUX基础命令
- B/S项目结束,又是一个新的开始
- sax解析xml字符串
- Wix打包系列(四) 自定义UI
- 使用v4包中的SwipeRefreshLayout为ListView和ScrollView添加下拉刷新功能
- 关于短信验证码的问题
- 如何创建一个Android原生的react-native组件(一)
- 查看mysql数据库版本方法总结
- 鼠标放在图片上,跟随鼠标显示大图,图片提示
- android---------Android中通过注解代替findViewById方法
- Java后台如何接收并处理前台传过来的json格式的数组参数
- Linux下tomcat 服务搭建
- 美国加息后A股大牛市?再等1-2年
- c运算符优先级
- 业务需求调研经验分享