常用宏定义
来源:互联网 发布:约瑟夫环 java 递归 编辑:程序博客网 时间:2024/05/16 06:09
常用宏定义
调试打印宏定义:CGRect、CGPoint、CGSize、CGRang
#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 SLLogRange(range) \SLLog(@"%s loc=%ld, len=%ld",#range,range.location,range.length)#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
颜色类
//———————————————————————颜色类———————————————————————————-----—————————————// 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)]// 安全释放#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__)
系统:获取系统版本、获取当前语言、判断是否 Retina屏,、判断是真机还是模拟器
//----------------------系统----------------------------//获取系统版本#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]//获取当前语言#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])//判断是否 Retina屏、设备是否%fhone 5、是否是iPad#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)//判断是真机还是模拟器#if TARGET_OS_IPHONE//iPhone Device#endif#if TARGET_IPHONE_SIMULATOR//iPhone Simulator#endif//检查系统版本#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
读取本地图片、定义UIImage对象
//读取本地图片#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:[UIUtil imageName:_pointer]]//建议使用前两种宏定义,性能高于后者//设置View的tag属性#define VIEWWITHTAG(_OBJECT, _TAG) [_OBJECT viewWithTag : _TAG]//程序的本地化,引用国际化的文件#define MyLocal(x, ...) NSLocalizedString(x, nil)
GCD
//G-C-D#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)//NSUserDefaults 实例化#define USER_DEFAULT [NSUserDefaults standardUserDefaults]//由角度获取弧度 有弧度获取角度#define degreesToRadian(x) (M_PI * (x) / 180.0)#define radianToDegrees(radian) (radian*180.0)/(M_PI)
0 0
- 常用宏定义函数
- 常用宏定义一览
- 常用宏定义
- 常用的宏定义
- 常用宏定义
- C常用宏定义!!!
- 常用系统宏定义
- 常用的宏定义
- 常用的宏定义
- IOS 常用宏定义
- iOS常用宏定义
- iOS 常用宏定义
- ios常用宏定义
- 常用系统宏定义
- IOS 常用宏定义
- IOS常用宏定义
- IOS 常用宏定义
- IOS常用宏定义
- uc/os-iii学习笔记-中断管理
- JEECG 3.6.5版本发布,企业级JAVA快速开发平台
- ImageLoader的简单分析(五)
- 欧拉回路路径求解
- React Native 学习笔记(二)
- 常用宏定义
- 阿里腾讯图谱“智能鉴黄”技术哪家强?
- poj3295
- [备注] 关于openssl的系统介绍
- org.apache.hadoop.security.AccessControlException 解决办法
- Android版本号 API level一览表
- 监督学习应用.梯度下降.
- 找工作的方法
- 自动生产serialVersionUID 的方法