iOS 開(kāi)發(fā)中常用的一些宏定義
1.關(guān)于設(shè)置顏色
//設(shè)置顏色
①.常見(jiàn)的方式
#define HHGlobalBackgroundColor [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0]
#define HHCommonColor [UIColor colorWithRed:152/255.0 green:158/255.0 blue:0/255.0 alpha:1.0]
②.書寫方便的宏
#define HHColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
③.16進(jìn)制RGB的顏色轉(zhuǎn)換 --->推薦使用
#define HHColorFromHex(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]
使用時(shí)直接調(diào)用宏定義:后面直接傳入 `0x(0~f)`
例如:[dateLabel setTextColor:ZNColorFromHex(0x989e00)];
④.隨機(jī)色
#define HHRandomColor JYJColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
2.自定義 Log
#ifdef DEBUG
#define HHLog(...) NSLog(__VA_ARGS__)
#else
#define HHLog(...)
#endif
#define HHLogFunc HHLog(@"%s",__func__);
//重寫HHNSLog,Debug模式下打印日志和當(dāng)前行數(shù)
#if DEBUG
#define HHNSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define HHNSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#endif
3.弱引用
#define HHWeakSelf __weak typeof(self) weakSelf = self
4.通知
#define HHNotiCenter [NSNotificationCenter defaultCenter]
5.UserDefault
#define HHUserDefaults [NSUserDefaults standardUserDefaults]
6.常用的寬高
#define HHScreenH [UIScreen mainScreen].bounds.size.height
#define HHScreenW [UIScreen mainScreen].bounds.size.width
#define HHScreenBounds [UIScreen mainScreen].bounds
#define HHKeyWindow [UIApplication sharedApplication].keyWindow
#define HHRootTabBarController (UITabBarController *)HHKeyWindow.rootViewController
7.OC 的框架
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#pragma mark - 頭文件
#import "xxxxxx" //放入要用的頭文件
#endif
8.沙盒路徑
#define HHCaches [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]
9.
內(nèi)容持續(xù)更新中,有用就拿走........順便點(diǎn)個(gè)贊,謝謝大家的支持!