iOS 常用的宏定义

2016-12-05  本文已影响43人  Helong

//获取屏幕的宽度、高度

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

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

//适配比例,以iphone6尺寸为基准

#define wl ([UIScreen mainScreen].bounds.size.width/375)

#define hl ([UIScreen mainScreen].bounds.size.height/667)

//DEBUG模式下打印日志

#ifdef DEBUG

#define HLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

#else

#define HLog(...)

#endif

//获取系统版本

#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

//判断设备操作系统是否为iOS7

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

//RGB颜色转换 (16进制->10进制)

#define UIColorFromRGBA(rgbValue, alphaValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0x00FF00) >> 8))/255.0 blue:((float)(rgbValue & 0x0000FF))/255.0 alpha:alphaValue]

//RGB颜色

#define RGBACOLOR(R,G,B,A) [UIColor colorWithRed:(R)/255.0 green:(G)/255.0 blue:(B)/255.0 alpha:(A)]

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

//整体背景色

#define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]

//清除背景色

#define CLEARCOLOR [UIColor clearColor]

#define WHITECOLOR [UIColor whiteColor]

//整体字体颜色,大小

#define TEXT_COLOR [UIColor colorWithRed:(51)/255.0 green:(71)/255.0 blue:(113)/255.0 alpha:1.0]

#define TEXT_FONT  [UIFont systemFontOfSize:14*hl]

#define Text_Font  [UIFont systemFontOfSize:12*hl]

//方正黑体简体字体定义

#define FONT(F) [UIFont fontWithName:@"FZHTJW--GB1-0" size:F]

//定义一个API

#define APIURL @""

//GCD

#define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)

#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

//NSUserDefaults 实例化

#define USER_DEFAULT [NSUserDefaults standardUserDefaults]

//由角度获取弧度 有弧度获取角度

#define angleToRadian(x) (M_PI*(x)/180.0)

#define radianToAngle(r) (r*180.0)/M_PI

//block块呢,self->weakSelf

#define WeakSelf __weak typeof(self) weakSelf = self;

自己常用的一些宏定义,拿出来记录一下,分享一下,万一有人需要呢!!

上一篇下一篇

猜你喜欢

热点阅读