iOS敏捷开发之道,经常使用的宏定义总结

摘要:
@(x) owner:YES)objectAtIndex:%@:[[NSStringstringWithUTF8String:[NSDatedate]]#defineCourrentYear[[NSCalendarcurrentCalendar]组件:

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敏捷开发之道,经常使用的宏定义总结》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇vue路由懒加载UDP广播-缓冲区过小下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Activemq Jolokia

打开JMX <broker … useJmx="true"> …   <managementContext>             <managementContext createConnector="true"/>     </managementContext> </broker> 启动A...

高性能JSON框架之FastJson的简单使用

转载 高性能JSON框架之FastJson的简单使用 1.前言1.1.FastJson的介绍:JSON协议使用方便,越来越流行,JSON的处理器有很多,这里我介绍一下FastJson,FastJson是阿里的开源框架,被不少企业使用,是一个极其优秀的Json框架,Github地址: FastJson 1.2.FastJson的特点:1.FastJson数度...

Nginx高并发简单配置

https://www.cnblogs.com/sunjianguo/p/8298283.html 停用除SSH外的所有服务,仅保留nginx,优化思路主要包括两个层面:系统层面+nginx层面。 1、调整同时打开文件数量 ulimit -n 20480 2、TCP最大连接数(somaxconn) echo 10000 > /proc/sys/net...

weex-iOS集成

weex-iOS集成 weex只是刚刚起步,还存在一些bug,有些功能还有待完善和提高.但是其使用起来还是可以节省些时间. 这里我们说说如何把weex集成到我们的iOS项目中 1. 下载weex源代码 git clone https://github.com/alibaba/weex.git 2. 把根目录下的/ios/sdk整个目录拷贝到项目中...

UITableview 上提刷新

最近做的项目中用到了列表,数据是要从webservice请求,网络是通过3G或者Wifi来连接,所以决定采用分页加载方式下载数据。 从网上找到的资料,基本思路就是在Tableview的末尾,也就是contentview(Tableview本身继承与Scrollview)的末尾,加一个footview,用来显示:“上拉加载更多数据”、“加载中“、"松开即加载...

linux文件系统

一、什么是文件系统 操作系统中用于管理和组织磁盘设备上文件的方法和数据结构叫做文件系统. 1.1 根文件系统(rootfs): 在Linux中, 文件系统和倒树形结构一样, 位于最顶层的的一个分区我们称之为根(root), 用于安装linux系统, 类似于Windos的系统盘; 根分区又叫做根文件系统(root filesystem). 根文件系统由内核...