ios中常用宏定义

  • 获取设备屏幕尺寸
    • #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
    • #define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
  • 获取系统版本
    • #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
  • 判断设备是否是iPhone/iPad
    • #define IPHONE ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone)
    • #define IPAD ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad)
  • 获取RGB颜色
    • #define RGBA(r,g,b,a) [UIColor colorWithRed:a/255.0f green:g/255.0f blue:b/255.0f alpha:a]
    • #define RGB(r,g,b) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:1.0]
  • 自定义log 输出方法名及所在行数
    • #define TYLog(…) NSLog(@“%s %@“,__func__ ,[NSString stringWithFormat:,__VA_ARGS__])
  • release 模式 屏蔽log
  • #ifdef DEBUG
    #else
     #define TYLog(…) NSLog(@“%s %@“,__fun __ ,[NSString stringWithFormat:,__VA_ARGS__])
     #endif