iOS 开发中常用的一些宏定义
1.关于设置颜色
//设置颜色
①.常见的方式
#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进制RGB的颜色转换 --->推荐使用
#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]
使用时直接调用宏定义:后面直接传入 `0x(0~f)`
例如:[dateLabel setTextColor:ZNColorFromHex(0x989e00)];
④.随机色
#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模式下打印日志和当前行数
#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.
内容持续更新中,有用就拿走........顺便点个赞,谢谢大家的支持!