开发常用宏 - iOS
以下是一些开发中会经常用到的宏,简单的进行了整理,为了今后可以更加方便的使用,从而提升开发的效率,不为此搭进去更多时间.
也希望有大家可以补充,从而使其更加强加!
/**
* 开发常用宏相关
*/ #ifndef FYHCommonMacros_h
#define FYHCommonMacros_h //开发的时候打印,但是发布的时候不打印的NSLog
#ifdef DEBUG
#define NSLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define NSLog(...)
#endif #pragma mark - Base
/** 弱引用*/
#define kWeakSelf(type) __weak typeof(type) weak##type = type;
/** 强引用*/
#define kStrongSelf(type) __strong typeof(type) type = weak##type;
/** 由角度转换弧度*/
#define kDegreesToRadian(x) (M_PI * (x) / 180.0)
/** 由弧度转换角度*/
#define kRadianToDegrees(radian) (radian * 180.0) / (M_PI) /** 获取一段时间间隔*/
#define kStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
#define kEndTime NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start) #pragma mark - Size
//获取屏幕宽度与高度
#define kScreenWidth \
([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreenmainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width)
#define kScreenHeight \
([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreenmainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height)
#define kScreenSize \
([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreenmainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreenmainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size) //屏幕 rect
#define SCREEN_RECT ([UIScreen mainScreen].bounds) #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) #define CONTENT_HEIGHT (SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - STATUS_BAR_HEIGHT) #pragma mark - Color
/** 颜色*/
#define kRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define kRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]
#define kRandomColor KRGBColor(arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0,arc4random_uniform(256)/255.0)
/** RGB*/
#define Main_Color [UIColor colorWithRed:(3)/255.0 green:(160)/255.0 blue:(235)/255.0 alpha:1.0]
#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 kColorWithHex(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] #pragma mark - Check
/** 字符串是否为空*/
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || str == NULL || [str isEqualToString:@"null"] || [str isEqualToString:@"<null>"] || [str isEqualToString:@"(null)"] || [str isEqualToString:@"nil"] || [str length] < 1 ? YES : NO )
/** 数组是否为空*/
#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
/** 字典是否为空*/
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
/** 是否是空对象*/
#define kObjectIsEmpty(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))
/** 判断是否为iPhone*/
#define kISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
/** 判断是否为iPad*/
#define kISiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
/** 判断是真机还是模拟器*/
#if TARGET_OS_IPHONE
//真机
#endif
#if TARGET_IPHONE_SIMULATOR
//模拟器
#endif
#pragma mark - 缩写
#define kApplication [UIApplication sharedApplication]
#define kKeyWindow [UIApplication sharedApplication].keyWindow
#define kAppDelegate ((AppDelegate*)[UIApplication sharedApplication].delegate)
#define kUserDefaults [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]
#pragma mark - 获取相关资料
/** APP版本号 Version*/
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
/** APP包版本号 BundleVersion*/
#define kAppBundle [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
/** 获取设备名称*/
#define kGetDeviceName [[UIDevice currentDevice] name]
/** 获取设备类型*/
#define kGetDeviceModel [[UIDevice currentDevice] model]
/** 获取设备 UUID*/
#define kGetDeviceUUID [[UIDevice currentDevice].identifierForVendor UUIDString]
/** 获取系统名称*/
#define kSystemName [[UIDevice currentDevice] systemName]
/** 系统版本号*/
#define kSystemVersion [[UIDevice currentDevice] systemVersion]
/** 获取当前语言*/
#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])
/** 获取沙盒 Document 路径*/
#define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
/** 获取沙盒 temp 路径(注:iPhone 重启会清空)*/
#define kTempPath NSTemporaryDirectory()
/** 获取沙盒 Cache 路径*/
#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]
/** 获取程序包中程序路径*/
#define kResource(f, t) [[NSBundle mainBundle] pathForResource:(f) ofType:(t)];
/** 获取系统时间戳*/
#define getCurrentTime [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]]
/** 屏幕分辨率*/
#define SCREEN_RESOLUTION (SCREEN_WIDTH * SCREEN_HEIGHT * ([UIScreen mainScreen].scale))
#endif /* FYHCommonMacros_h */
开发常用宏 - iOS的更多相关文章
- iOS 开发常用宏
来源:iOS_小松哥 链接:http://www.jianshu.com/p/be00c3f3cafd 大家都是知道使用宏不仅方便,而且可以提高开发效率.下面总结了iOS开发过程中的一些常用宏,会持续 ...
- Object-C开发常用宏定义
Object-C开发中宏会将经常用到的系统常量进行封装,方便使用: 1.获取通知中心 #define EYNotificationCenter(name, object, userInfo) [[NS ...
- iOS开发——常用宏的定义
有些时候,我们需要将代码简洁化,这样便于读代码.我们可以将一些不变的东东抽取出来,将变化的东西作为参数.定义为宏,这样在写的时候就简单多了. 下面例举了一些常用的宏定义和大家分享: 1. 判断设备的操 ...
- ios开发--常用宏定义(部分转)
1.release时,屏蔽log #if defined (DEBUG) && DEBUG == 1 #else #define NSLog(...) {}; #endif #if d ...
- IOS开发常用宏定义
//release屏蔽NSLog//放在.pch文件里#ifdef DEBUG #else#define NSLog(...) {};#endif //G.C.D#define BACK(block) ...
- ios 日常开发常用宏定义
#pragma mark - 字体.颜色相关 #define kFONT_SIZE(f) [UIFont systemFontOfSize:(f)] #define kFONT_BOLD_SIZE ...
- iOS常用宏 定义
总结了iOS开发过程中的一些常用宏,以后会陆陆续续添加进来. 字符串是否为空 1 #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull c ...
- iOS开发-常用第三方开源框架介绍(你了解的ios只是冰山一角)--(转)
图像: 1.图片浏览控件MWPhotoBrowser 实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网络下载图片并进行缓存.可对图片进行缩放等操作. 下 ...
- iOS开发-常用第三方开源框架介绍
iOS开发-常用第三方开源框架介绍 图像: 1.图片浏览控件MWPhotoBrowser 实现了一个照片浏览器类似 iOS 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网 ...
随机推荐
- 数据库的ACID跟事务隔离级别
摘抄:http://blog.csdn.net/shuaihj/article/details/14163713 ------------------------------------------- ...
- ip地址在通信中的变化(就简单的讲一下, 给自己mark)
节点之间的通信 数据报文的封装(自上而下) http tcp ip mac(讯框) 数据报文的源ip和目标ip是不变的(在内网中, 如果考虑到连接到外部网路的时候, 如果有路由器(里面有嵌入式的Lin ...
- REST与DDD
之前在为什么要使用MVC+REST+CQRS架构我曾经提出DDD是核心,REST是壳的观点,我想在这里详细谈谈我的思路. 今天正好看看到老外一篇博文Why REST is so important:按 ...
- IsPostBack详解
1.IsPostBack<只需要加载一次的代码放在if(!IsPostBack)中> 今天在最开始定义了全局变量取得radiobuttonlist中得到的value,但是因为autopos ...
- java-logic====吃货联盟
1.系统界面 2.功能一 3.查看餐袋 4.签收订单 5.删除订单 6.我要点赞 主要分在两个类中: 第一个类entity,主要的是一些共有的属性 主要代码: public class entity ...
- spring mvc改造成spring boot
一.新增依赖: <dependency> <groupId>org.springframework.boot</groupId> <artifactId> ...
- GitHub webstorm 及 README.md 姿势
README.md 语法格式: 规范的README文件开头都写上一个标题,这被称为大标题. 标题: #一级标题 ##二级标题 ###三级标题 ####四级标题 #####五级标题 ######六级标题 ...
- 《ArcGIS Runtime SDK for Android开发笔记》——(2)、Android Studio基本配置与使用
1.前言 在上一篇文章<Android Studio下载与安装>里我们已经介绍了Android Studio的下载与安装步骤,这一篇我们将针对Android Studio的基本常见使用做一 ...
- Python爬虫教程——入门五之URLError异常处理
大家好,本节在这里主要说的是URLError还有HTTPError,以及对它们的一些处理. 1.URLError 首先解释下URLError可能产生的原因: 网络无连接,即本机无法上网 连接不到特定的 ...
- Azure本月最新活动,速度Mark!!
缤纷五月,翠色盈盈,风光如画,小编在这里给大家汇总了这个多彩五月最新的活动合集.我们一切都准备好了,就等你来参加了~ 首先最重磅的当然是新一届的全球微软开发者大会! 有吃有喝有 Build,5 月 ...