iOS敏捷开发之道,经常使用的宏定义总结
iOS开发中,直接在pch文件里导入宏定义。
在做项目的时候,直接拿过来使用,能够大幅度提高开发速度。
以下是 个人总结的一些宏定义。
假设大家有其它的经常使用的宏定义。欢迎加入。我会定期更新这个blog…..
话不多说,直接上干货
// 在宏的參数前加上一个#。宏的參数会自己主动转换成c语言的字符串
#define MRKeyPath(objc,keyPath) @(((void)objc.keyPath, #keyPath))
//** 载入xib ***********************************************************************************
#define LoadNib(x) [[NSBundle mainBundle] loadNibNamed:@(x) owner:nil options:nil][0]
//** 沙盒路径 ***********************************************************************************
#define PATH_OF_APP_HOME NSHomeDirectory()
#define PATH_OF_TEMP NSTemporaryDirectory()
#define PATH_OF_DOCUMENT [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
//** DEBUG LOG *********************************************************************************
#ifdef DEBUG
#define MRLog( s, ... ) NSLog( @"< %@:(%d) > %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
#else
#define MRLog( s, ... )
#endif
//** 获得当前的 年 月 日 时 分 秒 *****************************************************************************
#define CurrentSec [[NSCalendar currentCalendar] component:NSCalendarUnitSecond fromDate:[NSDate date]]
#define CurrentMin [[NSCalendar currentCalendar] component:NSCalendarUnitMinute fromDate:[NSDate date]]
#define CurrentHour [[NSCalendar currentCalendar] component:NSCalendarUnitHour fromDate:[NSDate date]]
#define CurrentDay [[NSCalendar currentCalendar] component:NSCalendarUnitDay fromDate:[NSDate date]]
#define CurrentMonth [[NSCalendar currentCalendar] component:NSCalendarUnitMonth fromDate:[NSDate date]]
#define CurrentYear [[NSCalendar currentCalendar] component:NSCalendarUnitYear fromDate:[NSDate date]]
//** 角度转换成弧度 ******************************************************************************************
#define ANGEL(x) (x)/180.0 * M_PI
//* Frame (宏 x, y, width, height)**************************************************************************
// App Frame
#define Application_Frame [[UIScreen mainScreen] applicationFrame]
// App Frame Height&Width
#define App_Frame_Height [[UIScreen mainScreen] applicationFrame].size.height
#define App_Frame_Width [[UIScreen mainScreen] applicationFrame].size.width
// MainScreen Height&Width
#define Main_Screen_Height [[UIScreen mainScreen] bounds].size.height
#define Main_Screen_Width [[UIScreen mainScreen] bounds].size.width
// View 坐标(x,y)和宽高(width,height)
#define ViewxPos(v) (v).frame.origin.x
#define ViewyPos(v) (v).frame.origin.y
#define ViewWidth(v) (v).frame.size.width
#define ViewHeight(v) (v).frame.size.height
#define MinFrameX(v) CGRectGetMinX((v).frame)
#define MinFrameY(v) CGRectGetMinY((v).frame)
#define MidFrameX(v) CGRectGetMidX((v).frame)
#define MidFrameY(v) CGRectGetMidY((v).frame)
#define MaxFrameX(v) CGRectGetMaxX((v).frame)
#define MaxFrameY(v) CGRectGetMaxY((v).frame)
// 系统控件默认高度
#define kStatusBarHeight (20.f)
#define kTopBarHeight (44.f)
#define kBottomBarHeight (49.f)
#define kCellDefaultHeight (44.f)
#define kEnglishKeyboardHeight (216.f)
#define kChineseKeyboardHeight (252.f)
/* ****************************************************************************************************************** */
#pragma mark - Funtion Method (宏 方法)
// PNG JPG 图片路径
#define GetImagePathFromBundle(NAME) [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:NAME] ofType:nil]
#define GetExtPathFromBundle(NAME, EXT) [[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)]
// 颜色(RGB)
#define RgbColor(r, g, b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RgbColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
#define RandomColor [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1]
// View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]
// 当前版本号
#define FSystemVersion ([[[UIDevice currentDevice] systemVersion] floatValue])
#define DSystemVersion ([[[UIDevice currentDevice] systemVersion] doubleValue])
#define SSystemVersion ([[UIDevice currentDevice] systemVersion])
// 当前语言
#define CURRENTLANGUAGE ([[NSLocale preferredLanguages] objectAtIndex:0])
// 是否Retina屏
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? \
CGSizeEqualToSize(CGSizeMake(640, 960), \
[[UIScreen mainScreen] currentMode].size) : \
NO)
// 是否iPhone5
#define isiPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? \
CGSizeEqualToSize(CGSizeMake(640, 1136), \
[[UIScreen mainScreen] currentMode].size) : \
NO)
// 是否iPad
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// UIView - viewWithTag
#define VIEWWITHTAG(_OBJECT, _TAG) [_OBJECT viewWithTag : _TAG]
// 本地化字符串
/** NSLocalizedString宏做的事实上就是在当前bundle中查找资源文件名称“Localizable.strings”(參数:键+凝视) */
#define LocalString(x, ...) NSLocalizedString(x, nil)
/** NSLocalizedStringFromTable宏做的事实上就是在当前bundle中查找资源文件名称“xxx.strings”(參数:键+文件名称+凝视) */
#define AppLocalString(x, ...) NSLocalizedStringFromTable(x, @"someName", nil)
iOS敏捷开发之道,经常使用的宏定义总结的更多相关文章
- Android Studio快速开发之道
概述 现如今开发越来越追求效率和节奏,节省出时间做更多的事情,除了开发技术上的封装等,开发工具的使用技巧也是很重要的,今天就根据自己的经验来给大家介绍一下Android Studio快速开发之道. P ...
- iOS多线程开发之GCD(中篇)
前文回顾: 上篇博客讲到GCD的实现是由队列和任务两部分组成,其中获取队列的方式有两种,第一种是通过GCD的API的dispatch_queue_create函数生成Dispatch Queue:第二 ...
- iOS多线程开发之NSOperation - 快上车,没时间解释了!
一.什么是NSOperation? NSOperation是苹果提供的一套多线程解决方案.实际上NSOperation是基于GCD更高一层的封装,但是比GCD更加的面向对象.代码可读性更高.可控性更强 ...
- iOS游戏开发之UIDynamic
iOS游戏开发之UIDynamic 简介 什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟和仿真现实生活中的物理现象 ...
- iOS多线程开发之NSOperation
一.什么是NSOperation? NSOperation是苹果提供的一套多线程解决方案.实际上NSOperation是基于GCD更高一层的封装,但是比GCD更加的面向对象.代码可读性更高.可控性更强 ...
- iOS多线程开发之GCD(死锁篇)
上篇和中篇讲解了什么是GCD,如何使用GCD,这篇文章将讲解使用GCD中将遇到的死锁问题.有兴趣的朋友可以回顾<iOS多线程开发之GCD(上篇)>和<iOS多线程开发之GCD(中篇) ...
- iOS多线程开发之GCD(中级篇)
前文回顾: 上篇博客讲到GCD的实现是由队列和任务两部分组成,其中获取队列的方式有两种,第一种是通过GCD的API的dispatch_queue_create函数生成Dispatch Queue:第二 ...
- iOS_高效开发之道
iOS_高效开发之道 话不多说, 总结一下个人感觉有利于提高iOS开发效率的几个小技巧. 本文将从下面几方面介绍: Xcode经常使用快捷键 Xcode调试技巧 Objc经常使用代码片段 Xcode插 ...
- 敏捷开发之XP
敏捷方法论有一个共同的特点,那就是都将矛头指向了“文档”,它们认为传统的软件工程方法文档量太“重”了,称为“重量级”方法,而相应的敏捷方法则是“轻量级”方法.正是因为“轻量级”感觉没有什么力量,不但不 ...
随机推荐
- 十面阿里 Java 程序员,最终拿下阿里 P6 offer!
转子:https://mp.weixin.qq.com/s/RkMxPbm8E99-rTZKmvBy6Q 今天介绍小编的一个朋友,他现今有四年开发经验了,前前后后为了进阿里面试十次(阿里旗下—蚂蚁金服 ...
- css layout入门(转)
元素与盒 在HTML中常常使用的概念是元素,而在CSS中,布局的基本单位是盒,盒总是矩形的. 元素与盒并非一一对应的关系,一个元素可能生成多个盒,CSS规则中的伪元素也可能生成盒,display属性为 ...
- iOS 公司开发者账号申请清单
公司开发者账号申请清单: Apple ID账号申请: (有账号请提供账号密码) Apple ID: (最好是公司邮箱账号) Apple ID密码: (大于8位, 字母或数字组成, 包含 ...
- QEMU, a Fast and Portable Dynamic Translator
AbstractWe present the internals of QEMU, a fast machine emulator using an original portable dynamic ...
- Java 图片添加水印效果
package com.xiaowu.drawwater.demo; import java.awt.AlphaComposite; import java.awt.Graphics2D; impor ...
- lsof/fuser卸载挂载文件
Linux如何卸载挂载文件 在我们进行远程文件操作的时候,我们经常会出现文件服务出现卸载掉哦情况.例如 umount /mnt/net1umount: /mnt/net1: device is b ...
- phpunit与xdebug的使用
基本说明: 1.xdebug是程序猿在调试程序过程中使用的bug调试暴露工具 windows下安装: 1)下载php对应的dll文件,下载地址:https://xdebug.org/download. ...
- Java ActiveMQ队列模式案例
创建Eclipse项目并运行 创建java project:ActiveMQ-5.14,新建lib文件夹 打开apache-activemq-5.14.0-bin\apache-activemq-5. ...
- sipp中的action使用方法
最近在做sip服务器的压力测试 场景:当主叫收到200 Ok之后要将Contact 头域中的字段放在ACK消息中的请求行和to头域中发给被叫 查看sipp官网文档就使用action, 在主叫脚本中增加 ...
- Python闭包的高级应用-装饰器的实现
我们先看一个闭包的例子: from time import ctime def before_call(f): def wrapped(*args, **kargs): print 'before c ...