UtilsMacros.h
4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// UtilsMacro.h
// M16
//
#ifndef M16_UtilsMacro_h
#define M16_UtilsMacro_h
//Log utils marco
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define DLog(...)
#endif
#ifdef DEBUG
#define ULog(...)
//#define ULog(fmt, ...) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
#define ULog(...)
#endif
//System version utils
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
#define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_RETINA ([[UIScreen mainScreen] scale] >= 2.0)
#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)
#define IS_IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)
#define IS_IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)
#define IS_IPHONE_6_OR_MORE (IS_IPHONE && SCREEN_MAX_LENGTH >= 667.0)
#define IS_IPHONE_5_OR_MORE (IS_IPHONE && SCREEN_MAX_LENGTH >= 568.0)
//部分屏幕尺寸基于320等比例放大的尺寸
#define kScreenPointScale CGRectGetWidth([[UIScreen mainScreen] bounds])/320.0f
#define kScreenIs4 ([[UIScreen mainScreen] bounds].size.height == 480)
#define kScreenIs5 ([[UIScreen mainScreen] bounds].size.height == 568)
#define kScreenIs6 ([[UIScreen mainScreen] bounds].size.height == 667)
#define kScreenIs6plus ([[UIScreen mainScreen] bounds].size.height == 736)
#define kUserInterfaceIdiomIsPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
// 获取RGB颜色
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b) RGBA(r,g,b,1.0f)
#define IsPortrait ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
#define IsNilOrNull(_ref) (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]))
//角度转弧度
#define DEGREES_TO_RADIANS(d) (d * M_PI / 180)
//大于等于7.0的ios版本
#define iOS7_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")
//大于等于8.0的ios版本
#define iOS8_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")
//iOS6时,导航VC中view的起始高度
#define YH_HEIGHT (iOS7_OR_LATER ? 64:0)
#define kStatusBarHeight (20) //状态栏高度
#define kNavigationBarHeight (44) //NavBar高度
#define kTarBarHeight (49)
//获取系统时间戳
#define getCurentTime [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]]
#define FIRST_LUNCHED(v) ([NSString stringWithFormat:@"YH_FirstLunched_%@", v])
#define SeperateLineColor [UIColor m16_colorwithHexString:@"#e0e0e0"]
#define SeperateLineHeight IS_IPHONE_4_OR_LESS?1:0.5
//保护NSString不为空
#define MakeStringNotNil(str) (str?str:@"")
//非空判断
#define kUIAppearanceEnabled (NSProtocolFromString(@"UIAppearance") != nil)
#define IsNilOrNull(_ref) (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]))
#define IsDictionaryClass(_ref) (!IsNilOrNull(_ref) && ([(_ref) isKindOfClass:[NSDictionary class]]))
#define IsArrayClass(_ref) (!IsNilOrNull(_ref) && ([(_ref) isKindOfClass:[NSArray class]]))
#define IsStrEmpty(_ref) (IsNilOrNull(_ref) || (![(_ref) isKindOfClass:[NSString class]]) || ([(_ref) isEqualToString:@""]))
#define IsArrEmpty(_ref) (IsNilOrNull(_ref) || (![(_ref) isKindOfClass:[NSArray class]]) || ([(_ref) count] == 0))
#endif