一些常用的宏定义
来源:互联网 发布:电脑编程入门视频教程 编辑:程序博客网 时间:2024/05/17 01:37
宏定义
- // 安全释放
- #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
0 0
- 一些常用的宏定义
- 一些常用的宏定义
- 一些常用的宏定义
- 一些常用的宏定义
- 常用的一些宏定义
- 一些可以常用的宏定义
- iOS 一些常用的宏定义
- 位操作的一些常用宏定义
- 一些常用的定义文件
- 一些Java的常用定义
- 一些常用的宏定义(很有用,很有效噢)
- 一些常用的宏定义(很有帮助)
- IOS开发中常用的一些宏定义
- Cocos2dx常用的一些宏定义和头文件
- QString的一些常用定义方法
- 常用的宏定义
- 常用的宏定义
- 常用的宏定义
- MySQL设置环境变量 Windows XP
- linux内核模块编程常见问题
- Mule ESB 学习笔记mule和jersey的整合使用
- Android中Dialog的使用
- VirtualBox中安装CentOS使得在ssh和外网都能正常链接
- 一些常用的宏定义
- 内存不足:杀死进程还是牺牲子进程
- 解决a different object with the same identifier value was already associated with the session错误
- 在myeclipse中部署tomcat时, 出现错误为:Undefined exploded archive location
- C++可变参数...
- How to write a good bug report? Tips and Tricksa
- Eclipse—如何为Eclipse开发工具中创建的JavaWeb工程创建Servlet
- 写给年轻程序员的一封信
- 2011-06-30 17:50 SVN里恢复到某一天的版本操作