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敏捷开发之道,经常使用的宏定义总结的更多相关文章

  1. Android Studio快速开发之道

    概述 现如今开发越来越追求效率和节奏,节省出时间做更多的事情,除了开发技术上的封装等,开发工具的使用技巧也是很重要的,今天就根据自己的经验来给大家介绍一下Android Studio快速开发之道. P ...

  2. iOS多线程开发之GCD(中篇)

    前文回顾: 上篇博客讲到GCD的实现是由队列和任务两部分组成,其中获取队列的方式有两种,第一种是通过GCD的API的dispatch_queue_create函数生成Dispatch Queue:第二 ...

  3. iOS多线程开发之NSOperation - 快上车,没时间解释了!

    一.什么是NSOperation? NSOperation是苹果提供的一套多线程解决方案.实际上NSOperation是基于GCD更高一层的封装,但是比GCD更加的面向对象.代码可读性更高.可控性更强 ...

  4. iOS游戏开发之UIDynamic

    iOS游戏开发之UIDynamic 简介 什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能模拟和仿真现实生活中的物理现象 ...

  5. iOS多线程开发之NSOperation

    一.什么是NSOperation? NSOperation是苹果提供的一套多线程解决方案.实际上NSOperation是基于GCD更高一层的封装,但是比GCD更加的面向对象.代码可读性更高.可控性更强 ...

  6. iOS多线程开发之GCD(死锁篇)

    上篇和中篇讲解了什么是GCD,如何使用GCD,这篇文章将讲解使用GCD中将遇到的死锁问题.有兴趣的朋友可以回顾<iOS多线程开发之GCD(上篇)>和<iOS多线程开发之GCD(中篇) ...

  7. iOS多线程开发之GCD(中级篇)

    前文回顾: 上篇博客讲到GCD的实现是由队列和任务两部分组成,其中获取队列的方式有两种,第一种是通过GCD的API的dispatch_queue_create函数生成Dispatch Queue:第二 ...

  8. iOS_高效开发之道

    iOS_高效开发之道 话不多说, 总结一下个人感觉有利于提高iOS开发效率的几个小技巧. 本文将从下面几方面介绍: Xcode经常使用快捷键 Xcode调试技巧 Objc经常使用代码片段 Xcode插 ...

  9. 敏捷开发之XP

    敏捷方法论有一个共同的特点,那就是都将矛头指向了“文档”,它们认为传统的软件工程方法文档量太“重”了,称为“重量级”方法,而相应的敏捷方法则是“轻量级”方法.正是因为“轻量级”感觉没有什么力量,不但不 ...

随机推荐

  1. Exercise02_15

    import javax.swing.JOptionPane; public class Distance { public static void main(String[] args){ Stri ...

  2. TZOJ 5347: 数据结构实验:删除链表元素

    描述 完成链表的创建.元素查找和删除等操作. 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码. void PrintLinkList(Node *head) { int flag = 0; ...

  3. Problem T: 零起点学算法15——交换变量

    #include<stdio.h> int main() { int a,b,c; scanf("%d %d",&a,&b); c=a; a=b; b= ...

  4. ExtJS 4 在Ext.tab.Panel中使用Ext.ux.IFrame打开url指向的网页

    ext-4.2.1.883\examples\ux\IFrame.js ext-4.2.1.883\examples\ux\TabCloseMenu.js 复制到 \Scripts\ext-4.2.1 ...

  5. python中下划线_的用途

    Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx       不能用'from module import *'导入 __xxx__  系统定义名字 __xxx     类中的私有变量 ...

  6. Delphi 最小化程序到任务栏托盘 增加右键PopMenu

    在做中间层时,中间层往往不需要点击关闭时立刻关闭,而是最小化到托盘.故而特意隐藏关闭按钮功能. 1)隐藏退出功能 用PopMenu退出菜单代替 1.增加popMenu退出菜单,绑定到窗体 2.增加变量 ...

  7. mongodb 踩坑记录

    Map-Reduce Map-Reduce 是 mongodb 处理批量数据的大杀器,凡是数据量大并且定时处理能满足需求的,都可以试着扔给 mongodb,让它去 Map-Reduce. 以下截取自文 ...

  8. 你是那种仅仅看《XXXXX从入门到精通》的程序猿吗?

    我一開始又要废话一番了. 实际上上了大学以后.你常常会在网上,在和别人的交流里,在老师的课堂上.反复听到一些书,比方黄仁宇的<万历十五年>.王小波"时代三部曲".村上春 ...

  9. diskpart分盘代码

    List Disk Select Disk 0 Clean Create Partition Primary Size=512000 Active Format Quick Create Partit ...

  10. Unity3D使用TCP/IP协议,传递protocol buffer消息protobuf-net

    原文:http://my.oschina.net/faint/blog/296785 第一部分 dll 1 下面大多数内容,都是使用c#编译的dll来实现的. 2 编译为dll后,要拖放到unity3 ...