这里写了一些在iOS开发中经常用到的宏
//颜色
#define HEXCOLOR(hex) [UIColor colorWithRed:((float)((hex & 0xFF0000) >> 16)) / 255.0 green:((float)((hex & 0xFF00) >> 8)) / 255.0 blue:((float)(hex & 0xFF)) / 255.0 alpha:1]
//打印
#ifdef DEBUG
define DLog(fmt, …) NSLog((@"%s [Line %d] " fmt), PRETTY_FUNCTION, LINE, ##VA_ARGS)
#else
define DLog(…)
#endif
#define SCREEN_BOUNDS [[UIScreen mainScreen] bounds]
#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)
#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)
#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))
#define SCREEN_MIN_LENGTH (MIN(SCREEN_WIDTH, SCREEN_HEIGHT))
//苹果x
#define IPHONE_X
({BOOL isPhoneX = NO;
if (@available(iOS 11.0, *)) {
isPhoneX = [[UIApplication sharedApplication] delegate].window.safeAreaInsets.bottom > 0.0;
}
(isPhoneX);})
#define NavigationBarHeight (IPHONE_X ? 88 : 64)
// Views
///
#define WIDTH(view) view.frame.size.width
#define HEIGHT(view) view.frame.size.height
#define X(view) view.frame.origin.x
#define Y(view) view.frame.origin.y
#define LEFT(view) view.frame.origin.x
#define TOP(view) view.frame.origin.y
#define BOTTOM(view) (view.frame.origin.y + view.frame.size.height)
#define RIGHT(view) (view.frame.origin.x + view.frame.size.width)
/**
顶部安全区高度
/
#define SafeAreaTopHeight (IPHONE_X ? 44 : 20)
/
*底部安全区高度
*/
#define SafeAreaBottomHeight (IPHONE_X ? (34) : 0)
/**
导航栏高度(包括顶部安全区)
/
#define NavigationBarHeight (IPHONE_X ? 88 : 64)
/
*标签栏高度(包括底部安全区)
*/
#define TabbarHeight (IPHONE_X ? (34+49) : 49)