iOS_常用宏定义汇总
2015-11-17 17:19
204 查看
#pragma mark ===============常用的宏定义================
#define kScreenHeight [[UIScreen mainScreen] bounds].size.height
#define kScreenWidth [[UIScreen mainScreen] bounds].size.width
#define kStateBarHeight 20
#define kMainHeight (ScreenHeight - StateBarHeight)
#define kMainWidth ScreenWidth
//是否为retina
#define isRetina ([UIScreen instancesRespondToSelector:
@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960),
[[UIScreen mainScreen] currentMode].size) : NO)
//是否为7.0系统
#define IsIOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >=7.0 ? YES : NO)
//RGB色值
#define BACKGROUND_CORLOR [UIColor colorWithRed:222.0/255 green:222.0/255 blue:222.0/255 alpha:1]
//16进制色值
#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]
//保存本地
#define kUserDefault [NSUserDefaults standardUserDefaults]
#define kApplication [UIApplication sharedApplication]
#define kDataEnv [DataEnvironment sharedDataEnvironment]
#define kDegreesToRadian(x) (M_PI * (x) / 180.0)
//弧度
#define kRadianToDegrees(radian) (radian*180.0)/(M_PI)
//根据名称加载有缓存图片
#define kImageNamed(name) [UIImage imageNamed:name]
//判断系统的当前版本。
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#pragma mark ===============不常用的宏定义================
#define kSystemError @"系统繁忙,请稍后再试!"
//获取系统目录
#define kGetDirectory(NSSearchPathDirectory) [NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory, NSUserDomainMask, YES)lastObject]
//获取NSFILEMANAGER对象
#define kFileManager [NSFileManager defaultManager]
//获取程序代理
#define kAppdelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
// 获取任意WINDOW对象
#define kWindow [[[UIApplication sharedApplication] windows] lastObject]
//获取KEYWINDOW对象
#define kKeyWindow [[UIApplication sharedApplication] keyWindow]
//获取USERDEFAULTS对象
#define kNotificactionCenter [NSNotificationCenter defaultCenter]
// 获取当前控制器的navigationBar
#define kNavigationBar [[self navigationController] navigationBar]
//简单提示框
#define kAlert(title, msg) [[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]show]
-----------------------------------加载图片-----------------------------------
//根据名称加载无缓存图片
#define kNoCacheImagewithName(name, ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:name ofType:ext]]
// 根据路径加载无缓存图片
#define kNoCacheImagewithPath(path) [UIImage imageWithContentsOfFile:path]
-----------------------------------视图-----------------------------------
// 根据TAG获取视图
#define kViewWithTag(PARENTVIEW, TAG, CLASS) ((CLASS *)[PARENTVIEW viewWithTag:TAG])
// 加载NIB文件
#define kLOADNIBWITHNAME(CLASS, OWNER) [[[NSBundle mainBundle] loadNibNamed:CLASS owner:OWNER options:nil] lastObject]
// 异步
#define kGCDAsync(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
// 同步
#define kGCDMain(block) dispatch_async(dispatch_get_main_queue(),block)
-----------------------------------界面尺寸--------------------------------------
//导航栏高度
#define kNavigationBarHeight 44
// 工具栏高度
#define kTabBarHeight 49
// 是否IPad
#define kIsIpad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// 是否IPhone
#define kIsIphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
// 获取系统信息
#define kSystemVersion [[UIDevice currentDevice] systemVersion]
// 获取当前语言环境
#define kCurrentLanguage [[NSLocale preferredLanguages] objectAtIndex:0]
// 获取当前APP版本
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
//调试相关
#ifdef DEBUG
#define XLOG(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define XLOG(...);
#endif
#define kScreenHeight [[UIScreen mainScreen] bounds].size.height
#define kScreenWidth [[UIScreen mainScreen] bounds].size.width
#define kStateBarHeight 20
#define kMainHeight (ScreenHeight - StateBarHeight)
#define kMainWidth ScreenWidth
//是否为retina
#define isRetina ([UIScreen instancesRespondToSelector:
@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960),
[[UIScreen mainScreen] currentMode].size) : NO)
//是否为7.0系统
#define IsIOS7 ([[[UIDevice currentDevice] systemVersion] floatValue] >=7.0 ? YES : NO)
//RGB色值
#define BACKGROUND_CORLOR [UIColor colorWithRed:222.0/255 green:222.0/255 blue:222.0/255 alpha:1]
//16进制色值
#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]
//保存本地
#define kUserDefault [NSUserDefaults standardUserDefaults]
#define kApplication [UIApplication sharedApplication]
#define kDataEnv [DataEnvironment sharedDataEnvironment]
#define kDegreesToRadian(x) (M_PI * (x) / 180.0)
//弧度
#define kRadianToDegrees(radian) (radian*180.0)/(M_PI)
//根据名称加载有缓存图片
#define kImageNamed(name) [UIImage imageNamed:name]
//判断系统的当前版本。
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#pragma mark ===============不常用的宏定义================
#define kSystemError @"系统繁忙,请稍后再试!"
//获取系统目录
#define kGetDirectory(NSSearchPathDirectory) [NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory, NSUserDomainMask, YES)lastObject]
//获取NSFILEMANAGER对象
#define kFileManager [NSFileManager defaultManager]
//获取程序代理
#define kAppdelegate ((AppDelegate *)[[UIApplication sharedApplication] delegate])
// 获取任意WINDOW对象
#define kWindow [[[UIApplication sharedApplication] windows] lastObject]
//获取KEYWINDOW对象
#define kKeyWindow [[UIApplication sharedApplication] keyWindow]
//获取USERDEFAULTS对象
#define kNotificactionCenter [NSNotificationCenter defaultCenter]
// 获取当前控制器的navigationBar
#define kNavigationBar [[self navigationController] navigationBar]
//简单提示框
#define kAlert(title, msg) [[[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil]show]
-----------------------------------加载图片-----------------------------------
//根据名称加载无缓存图片
#define kNoCacheImagewithName(name, ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:name ofType:ext]]
// 根据路径加载无缓存图片
#define kNoCacheImagewithPath(path) [UIImage imageWithContentsOfFile:path]
-----------------------------------视图-----------------------------------
// 根据TAG获取视图
#define kViewWithTag(PARENTVIEW, TAG, CLASS) ((CLASS *)[PARENTVIEW viewWithTag:TAG])
// 加载NIB文件
#define kLOADNIBWITHNAME(CLASS, OWNER) [[[NSBundle mainBundle] loadNibNamed:CLASS owner:OWNER options:nil] lastObject]
// 异步
#define kGCDAsync(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
// 同步
#define kGCDMain(block) dispatch_async(dispatch_get_main_queue(),block)
-----------------------------------界面尺寸--------------------------------------
//导航栏高度
#define kNavigationBarHeight 44
// 工具栏高度
#define kTabBarHeight 49
// 是否IPad
#define kIsIpad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// 是否IPhone
#define kIsIphone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
// 获取系统信息
#define kSystemVersion [[UIDevice currentDevice] systemVersion]
// 获取当前语言环境
#define kCurrentLanguage [[NSLocale preferredLanguages] objectAtIndex:0]
// 获取当前APP版本
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
//调试相关
#ifdef DEBUG
#define XLOG(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define XLOG(...);
#endif
相关文章推荐
- iOS开发使用自己添加的字体
- ios测试基础四:crash日志分析
- ios 剪裁图片
- 仿ios分段选择器(自定义radiogroup)
- iOS_数据持久化
- iOS开发获取电池电量
- iOS日期的比较
- iOS开发中数据持久化方案小结
- iOS-----使用addressBook管理联系人之修改联系人
- iOS提交后申请加急审核
- xcode7/ios9中 低版本app运行时,屏幕上下出现黑边的问题
- 成为合法的苹果开发者
- cocoaPods做iOS程序的依赖管理
- Foundation框架之 NSString 和 集合
- iOS相册图片的选取与设置
- iOS_一些简单地功能代码
- ios 滑动返回出现问题以及解决方法
- iOS播放gif图
- iOS开发页面传值方案
- 我是怎样转IOS应用开发的