zoukankan      html  css  js  c++  java
  • iOS开发中的常用宏定义

    在iOS开发的过程中合理的使用宏定义能够极大提高编码的速度,下面是一些常用的宏定义,部分内容来自互联网

    Log

    //  调试状态, 打开LOG功能
    #ifdef DEBUG
    #define GLLog(...) NSLog(__VA_ARGS__)
    #define GLLogMethod NSLog(@"%s", __func__)
    #else
    //  发布状态, 关闭LOG功能
    #define GLLog(...)
    #define GLLogMethod
    #endif
    

    颜色

    #define RGB(r,g,b) [UIColor colorWithRed:r/255. green:g/255. blue:b/255. alpha:1.]
    
    #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255. green:g/255. blue:b/255. alpha:a/100.]
    
    //16进制的颜色
    #define RGBHex(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0] 
    
    //主颜色
    #define MainColor RGB(107,185,103)
    //主背景色
    #define MainBgColor RGB(238,240,243)
    
    

    屏幕的长度和宽度

    #define UIHeight [[UIScreen mainScreen] bounds].size.height
    #define UIWidth [[UIScreen mainScreen] bounds].size.width
    

    字体font

    #define kFont(x) [UIFont systemFontOfSize:x]
    #define kBoldFont(x) [UIFont boldSystemFontOfSize:x]
    
    #define MainFont14 [UIFont systemFontOfSize:14]
    #define MainFont15 [UIFont systemFontOfSize:15]
    #define MainFont12 [UIFont systemFontOfSize:12]
    
    

    app名字及版本号

    //app名字
    #define AppName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"]
    //app版本号
    #define AppVersion [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString*)kCFBundleVersionKey]
    

    尺寸适配

    #define Match(x) (x * UIWidth / 320)
    

    其他

    //通知中心
    #define GLNotifyCenter [NSNotificationCenter defaultCenter]
    
    //main bundle加载xib文件
    #define MainBundle(xx) [[[NSBundle mainBundle] loadNibNamed:xx owner:self options:nil] lastObject]
    
    //个人设置中心
    #define GLUserCenter [NSUserDefaults standardUserDefaults]
    
    //weakSelf
    #define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self;
    
  • 相关阅读:
    c# 反射取其他项目的资源文件
    【分享】免费建立自己的站点
    c# 自定义类型的DataBindings
    ListView 多行拖拽排序
    linq to sql之组装where条件下的'或'语句
    dotfuscator使用方法
    orderBy 传入属性的字符串
    WCF数据交互时长度超过8192
    ASP.net中aspx与cs函数的互调
    c# 读取excel数据的两种方法
  • 原文地址:https://www.cnblogs.com/iyou/p/4818022.html
Copyright © 2011-2022 走看看