美文网首页
常用iOS宏定义

常用iOS宏定义

作者: 不愿透漏姓名的s | 来源:发表于2017-03-06 11:21 被阅读27次
    IMG_2384.JPG

    1.获取屏幕高度和宽度

    #define kScreenHeight [[UIScreen mainScreen] bounds].size.height
    #define kScreenWidth [[UIScreen mainScreen] bounds].size.width
    

    2.设置字体和字体大小

    #define CHINESE_FONT_NAME  @"Heiti SC"
    #define CHINESE_SYSTEM(x) [UIFont fontWithName:CHINESE_FONT_NAME size:x]
    #define BOLDSYSTEMFONT(FONTSIZE) [UIFont boldSystemFontOfSize:FONTSIZE]
    #define SYSTEMFONT(FONTSIZE)     [UIFont systemFontOfSize:FONTSIZE]
    #define FONT(NAME, FONTSIZE)     [UIFont fontWithName:(NAME) size:(FONTSIZE)]
    

    3.颜色HEX,RGB,RANDOM

    #define HEXCOLOR(rgbvalue) [UIColor colorWithRed:(CGFloat)((rgbvalue&0xFF0000)>>16)/255.0 green:(CGFloat)((rgbvalue&0xFF00)>>8)/255.0 blue:(CGFloat)(rgbvalue&0xFF)/255.0 alpha:1]
    #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 RANDOMCOLOR [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
    

    4.开发时打印,发布时不打印的NSLog

    #ifdef DEBUG
    #define LKLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
    #else
    #define LKLog(...)
    #endif
    

    5.获取图片资源

    #define IMG_NAME(name) [UIImage imageNamed:[NSString stringWithFormat:@"%@", name]]
    

    6.判断机型

    #define iPhone5 kScreenWidth == 320.0f && kScreenHeight == 568.0f
    #define iPhone6_7 kScreenWidth == 375.0f && kScreenHeight == 667.0f
    #define iPhone6P_7P kScreenWidth == 414.0f && kScreenHeight == 736.0f
    

    7.沙盒目录

    //获取沙盒 Document
    #define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
    //获取temp
    #define kPathTemp NSTemporaryDirectory()
    //获取沙盒 Cache
    #define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
    

    8.App版本

    #define AppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
    

    9.系统版本

    #define FSystemVersion    ([[[UIDevice currentDevice] systemVersion] floatValue])
    #define DSystemVersion    ([[[UIDevice currentDevice] systemVersion] doubleValue])
    #define SSystemVersion    ([[UIDevice currentDevice] systemVersion])
    

    相关文章

      网友评论

          本文标题:常用iOS宏定义

          本文链接:https://www.haomeiwen.com/subject/ezwygttx.html