目录
1.1 屏幕宽高
1.2 系统版本号判断
1.3 颜色相关
1.4 单例定义
1.5 NSLog修改
1.6 Block强弱引用
1.7 初始化可变数组、字典
1.8 URL定义
1.9 字体大小
1.10 字体颜色
1.11 时间相关
1.12 打印某一行
1.1 屏幕宽高
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width //屏幕宽度
#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height //屏幕高度
#define HEIGHT4 480
#define HEIGHT5 568
#define HEIGHT6 667
#define HEIGHT6P 736
1.2 系统版本号判断
#define IOS_SYSTEM_VERSION [[UIDevice currentDevice]systemVersion].floatValue
#define IOS7 [[UIDevice currentDevice]systemVersion].floatValue>=7.0
1.3 颜色相关
#define RGB(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB_HEX(value)[UIColor colorWithRed:((float)((value&0xFF0000)>>16))/255.0 green:((float)((value&0xFF00)>>8))/255.0 blue:((float)(value&0xFF))/255.0 alpha:1.0]
读取本地图片
#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]
1.4 单例定义
.h
#define ARC_SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(SS_CLASSNAME) \
+ (SS_CLASSNAME *)sharedInstance;
.m
#define ARC_SYNTHESIZE_SINGLETON_FOR_CLASS(SS_CLASSNAME) \
+ (SS_CLASSNAME *)sharedInstance { \
static SS_CLASSNAME *_##SS_CLASSNAME##_sharedInstance = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
_##SS_CLASSNAME##_sharedInstance = [[self alloc] init]; \
}); \
return _##SS_CLASSNAME##_sharedInstance; \
}
.h使用
ARC_SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(JDManager)
.m使用
ARC_SYNTHESIZE_SINGLETON_FOR_CLASS(JDManager)
1.5 NSLog修改
#ifdef DEBUG
#define JDLog(format, ...) do { \
fprintf(stderr, "< %s : %d > %s\n", \
[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], \
__LINE__, __func__); \
(NSLog)((format), ##__VA_ARGS__); \
fprintf(stderr, "\n"); \
} while (0)
#else
// release模式下关闭DEBUG
#define JDLog(format, ...) do{}while(0)
#endif
1.6 Block强弱引用
#define SELF_STRONG() __strong typeof(weakSelf)strongSelf = weakSelf
#define SELF_BLOCK() __block __typeof(&*self)blockSelf = self
#define SELF_WEAK() __weak __typeof(&*self)weakSelf = self
1.7 初始化可变数组、字典
#define INIT_ARRAY [[NSMutableArray alloc]initWithCapacity:0]
#define INIT_DICTIONARY [NSMutableDictionary dictionaryWithCapacity:0]
1.8 URL定义
#define API_DOMAIN @"xxx.liujiada.com" //正式线
//#define API_DOMAIN @"90.50.45.30:8089" //测试线
#define HISTORY @"http://"API_DOMAIN@"/xxx/listHistory" //历史版本
1.9 字体大小
#define FontSizeLarge_xxxxx [UIFont systemFontOfSize:49]
#define FontSizeLarge_xxxx [UIFont systemFontOfSize:34]
#define FontSizeLarge_xxx [UIFont systemFontOfSize:26]
#define FontSizeLarge_xx [UIFont systemFontOfSize:21]
#define FontSizeLarge_x [UIFont systemFontOfSize:19]
#define FontSizeLarge [UIFont systemFontOfSize:16]
#define FontSizeMedium [UIFont systemFontOfSize:14]
#define FontSizeSmall [UIFont systemFontOfSize:12]
#define FontSizeSmall_s [UIFont systemFontOfSize:10]
//=======加粗
#define BoldFontSizeLarge_x [UIFont boldSystemFontOfSize:19]
#define BoldFontSizeLarge [UIFont boldSystemFontOfSize:16]
#define BoldFontSizeMedium [UIFont boldSystemFontOfSize:14]
#define BoldFontSizeSmall [UIFont boldSystemFontOfSize:12]
1.10 字体颜色
#define ColorOrange 0xfa8919
#define ColorLightOrange 0xffa033
#define ColorWhite 0xffffff
#define ColorLightGray_ssss 0xfafafa
#define ColorLightGray_sss 0xf0f0f0
#define ColorLightGray_ss_l 0xebebeb
#define ColorLightGray_ss 0xe5e5e5
#define ColorLightGray_s 0xcccccc
#define ColorLightGray 0xadadad
#define ColorLinkGray 0x878787
#define ColorGray 0x666666
#define ColorDarkGray 0x333333
#define ColorRed 0xfa2419
#define ColorGreen 0x52b786
#define ColorRed_start 0xe37479
1.11 时间相关
#define getCurentTime [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]] //获取当前时间戳
1.12 打印出具体哪了类
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"[%s:%d行] %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif