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

    ios讨论群1群:135718460

    有些时候。我们须要将代码简洁化,这样便于读代码。我们能够将一些不变的东东抽取出来。将变化的东西作为參数。

    定义为宏,这样在写的时候就简单多了。


    以下例举了一些经常使用的宏定义和大家分享:

    1. 推断设备的操作系统是不是ios7

    #define IOS7   (  [[[UIDevice currentDevice].systemVersion doubleValue] >= 7.0] )

    2. 推断当前设备是不是iPhone5 

    #define kScreenIphone5    (([[UIScreen mainScreen] bounds].size.height)>=568)




    3.获取当前屏幕的高度
    #define kMainScreenHeight ([UIScreen mainScreen].applicationFrame.size.height)

    4.获取当前屏幕的宽度

    #define kMainScreenWidth  ([UIScreen mainScreen].applicationFrame.size.width)

    5.获得RGB颜色

    #define SMSColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]


    6..自己定义Log

    #ifdef DEBUG

    #define SMSLog(...) NSLog(__VA_ARGS__)

    #else

    #define SMSLog(...)

    #endif


    7.单例

    // @interface
    #define singleton_interface(className) 
    + (className *)shared##className;
    
    
    // @implementation
    #define singleton_implementation(className) 
    static className *_instance; 
    + (id)allocWithZone:(struct _NSZone *)zone 
    { 
        static dispatch_once_t onceToken; 
        dispatch_once(&onceToken, ^{ 
            _instance = [super allocWithZone:zone]; 
        }); 
        return _instance; 
    } 
    + (className *)shared##className 
    { 
        static dispatch_once_t onceToken; 
        dispatch_once(&onceToken, ^{ 
            _instance = [[self alloc] init]; 
        }); 
        return _instance; 
    }




  • 相关阅读:
    关于轨道交通的一些知识点和关键词
    关于芯片的一些关键词
    关于ADC采集
    Linux记录
    在VMware运行Linux下,密码错误的原因
    气体传感器
    AD采集问题
    Maven [ERROR] 不再支持源选项 5,请使用 7 或更高版本的解决办法
    Maven 专题(九):后记
    Maven 专题(六):Maven核心概念详解(二)
  • 原文地址:https://www.cnblogs.com/zhchoutai/p/7223550.html
Copyright © 2011-2022 走看看