美文网首页
iOS开发常用宏

iOS开发常用宏

作者: CoderHong | 来源:发表于2017-10-18 14:32 被阅读3次

    Debug与Release

    #ifdef DEBUG
        NSLog(@"--------------DEBUG");
    #else
        NSLog(@"--------------RELEASE");
    #endif
    

    自定义NSLog

    #ifdef DEBUG
    #define HTLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
    #else
    #define HTLog(...)
    #endif
    

    屏幕宽度

    #define SCREEN_WIDTH   [UIScreen mainScreen].bounds.size.width
    
    #define SCREENH_HEIGHT [UIScreen mainScreen].bounds.size.height
    

    颜色设置

    // 随机色
    #define HTRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
    
    // RGB颜色/设置RGBA颜色
    #define HTRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
    
    #define HTRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]
    

    沙盒路径

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

    相关文章

      网友评论

          本文标题:iOS开发常用宏

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