ios常用宏定义
2015-12-10 11:20
471 查看
[code]//------------------------单利宏定义-------------------------- #define IMPLEMENT_SINGLETON(class)\ + (instancetype)shared##class {\ static class* shared##class = nil;\ static dispatch_once_t onceToken;\ dispatch_once(&onceToken, ^{\ shared##class = [[self alloc] init];\ });\ return shared##class;\ } //单利的使用方法,直接里面加类名就可以了 IMPLEMENT_SINGLETON(AppManager) //-----------------------UIView 一些操作方法**----------------- #define ScreenWidth [[UIScreen mainScreen] bounds].size.width #define ScreenHeight [[UIScreen mainScreen] bounds].size.height #define iOSVersion [[UIDevice currentDevice].systemVersion floatValue] #define CGRectSetWidth(rect, width) CGRectMake(rect.origin.x, rect.origin.y, width, rect.size.height) #define CGRectSetHeight(rect, height) CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, height) #define CGRectSetSize(rect, size) CGRectMake(rect.origin.x, rect.origin.y, size.width, size.height) #define CGRectSetX(rect, x) CGRectMake(x, rect.origin.y, rect.size.width, rect.size.height) #define CGRectSetY(rect, y) CGRectMake(rect.origin.x, y, rect.size.width, rect.size.height) #define CGRectSetOrigin(rect, origin) CGRectMake(origin.x, origin.y, rect.size.width, rect.size.height) #define ViewSetWidth(view, width) view.frame = CGRectSetWidth(view.frame, width); #define ViewSetHeight(view, height) view.frame = CGRectSetHeight(view.frame, height); #define ViewSetSize(view, size) view.frame = CGRectSetSize(view.frame, size); #define ViewSetX(view, x) view.frame = CGRectSetX(view.frame, x); #define ViewSetY(view, y) view.frame = CGRectSetY(view.frame, y); #define ViewSetOrigin(view, origin) view.frame = CGRectSetOrigin(view.frame, origin); //----------------------system---------------------------- //获取系统版本 #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) //----------------------图片---------------------------- //读取本地图片 #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]] //建议使用前两种宏定义,性能高于后者 // 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] //file //读取文件的文本内容,默认编码为UTF-8 #define FileString(name,ext) [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)] encoding:NSUTF8StringEncoding error:nil] #define FileDictionary(name,ext) [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]] #define FileArray(name,ext) [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]] //App #define kApp ((AppDelegate *)[UIApplication sharedApplication].delegate) #define kNav ((AppDelegate *)[UIApplication sharedApplication].delegate.navigationController) //拨打电话 #define canTel ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"tel:"]]) #define tel(phoneNumber) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNumber]]]) #define telprompt(phoneNumber) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt:%@",phoneNumber]]]) //打开URL #define canOpenURL(appScheme) ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:appScheme]]) #define openURL(appScheme) ([[UIApplication sharedApplication] openURL:[NSURL URLWithString:appScheme]])
相关文章推荐
- iOS 之 AutoresizesSubviews ——自动尺寸调整行为
- ios 一些简单的 方法
- iOS开发经验积累 二
- iOS 修改包名称
- iOS 视频简单的播放
- iOS Block
- iOS 事件处理机制与图像渲染过程
- 转:ios的图片文件上传代码
- iOS 绘制虚线
- iOS应用版本更新
- iOS 8.3 ios9 横屏弹出alertview 崩溃问题
- IOS开发中的CGFloat、CGPoint、CGSize和CGRect
- iOS开发之多线程总结
- [iOS]iOS获取设备信息常用方法
- iOS: How To Make AutoLayout Work On A ScrollView
- iOS Core Animation分析与详解
- iOS开发之本地化
- iOS自定义TabBar
- IOS-40-测试环境与正式环境的代码通过标示符来区分
- 获得ios屏幕宽度