开发常用宏 - 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 自带的相册应用,可显示来自手机的图片或者是网络图片,可自动从网 ...
随机推荐
- RTT之柿饼UI
console.log("strings")//向单片机通过串口发送日志提示信息 this.setData({label1: { value : "Hello RT-Th ...
- 学习用node.js建立一个简单的web服务器
一.建立简单的Web服务器涉及到Node.js的一些基本知识点: 1.请求模块 在Node.js中,系统提供了许多有用的模块(当然你也可以用JavaScript编写自己的模块,以后的章节我们将详细讲解 ...
- logback配置说明
我觉得对于logback大家不太明白的有:过滤器.logger和root以及其中的一些属性的关系.其他的应该不是多迷糊,所以我就主要说说这几个的关系,并且为了清晰我只说控制台日志,写到文件的日志配置大 ...
- SEO搜索引擎
搜索引擎 搜索引擎(Search Engine)是指根据一定的策略.运用特定的计算机程序从互联网上搜集信息,在对信息进行组织和处理后,为用户提供检索服务,将用户检索相关的信息展示给用户的系统.搜索引擎 ...
- SVN中建立项目
下午建个svn的时候,出错,有个东西配置错了,晚上google看到一篇文章,觉得作者写的不错,而且很用心,转来共享. [转至]5分钟快速建立项目版本控制 – Face Code,Brain bloom ...
- Design Pattern ->Abstract Factory
Layering & Contract Philosophy With additional indirection Abstract Factory //The example code i ...
- 使用GreenDao 添加字段,删除表,新增表操作
GreenDao 给我个人感觉 比一般的ORM框架要好很多,虽然说上手和其他的比起来,较复杂,但是如果使用熟练以后,你会爱上这个框架的 用这些ORM 框架给我的感觉都是,当升级时,都需要进行数据库所有 ...
- Eclipse+ADT+Android SDK 搭建安卓开发环境(转)
要求 必备知识 windows 7 基本操作. 运行环境 windows 7(64位); eclipse-jee-luna-SR2-win32(32位);ADT-23.0.4 下载地址 环境下载 最近 ...
- 【QT】Qaction和触发函数建立连接的方法
说明:我是在ui里面编辑好控件以及位置,然后在程序里面将控件和触发函数进行绑定,实现的触发操作. 代码如下: MainWindow::MainWindow(QWidget *parent) : QMa ...
- 搭建日志环境并配置显示DDL语句
现在一般用log4j用的比较多,用slf4j用的比较少,所有这里我们就不用 hibernate内置的slf4j了. 用到slf的接口,log4j的实现. 要在hibernate中使用log4j,如图所 ...