iOS 常用的宏定義

//獲取屏幕的寬度、高度

#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;

自己常用的一些宏定義,拿出來記錄一下,分享一下,萬一有人需要呢!!

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容