• 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)
  • 相关阅读:
    思维体操:用c#简单实现按一定规则输出有序数列
    浅谈c#中使用lock的是与非
    强大的在线IDE:CodeRun
    【百度地图API】如何利用地图API制作汽车沿道路行驶的动画?——如何获得道路层数据
    如何利用【百度地图API】,制作房产酒店地图?(中)——使用右侧列表打开信息窗口
    如何利用【百度地图API】,制作房产酒店地图?(下)——结合自己的数据库
    【百度地图API】如何制作“从这里出发”“到这里去”——公交篇
    【百度地图API】建立全国银行位置查询系统(五)——如何更改百度地图的信息窗口内容?
    如何利用【百度地图API】,制作房产酒店地图?(上)——制作自定义标注和自定义信息窗口
    【百度地图API】交你如何用百度地图搜索自己的数据!不需数据库!
  • 原文地址:https://www.cnblogs.com/wzjhoutai/p/7264291.html
Copyright © 2020-2023  润新知