#define IS_iPhoneX ([UIScreen mainScreen].bounds.size.width == 375 && [UIScreen mainScreen].bounds.size.height == 812)
#define IPHONEX_MARGIN_TOP (88)
#define IPHONEX_MARGIN_BOTTOM (34)
// App Frame
#define Application_Frame [[UIScreen mainScreen] applicationFrame]
// App Frame Height&Width
#define App_Frame_Height [[UIScreen mainScreen] applicationFrame].size.height
#define App_Frame_Width [[UIScreen mainScreen] applicationFrame].size.width
// MainScreen Height&Width
#define Screen_Height [[UIScreen mainScreen] bounds].size.height
#define Screen_Width [[UIScreen mainScreen] bounds].size.width
/**
* IphoneX适配
*/
#define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
/**
* 状态栏高度
*/
#define STATUS_BAR_HEIGHT (iPhoneX ? 44.f : 20.f)
/**
* 导航栏高度
*/
#define NAVIGATION_BAR_HEIGHT (iPhoneX ? 88.f : 64.f)
/**
* tabBar高度
*/
#define TAB_BAR_HEIGHT (iPhoneX ? (49.f+34.f) : 49.f)
/**
* home indicator
*/
#define HOME_INDICATOR_HEIGHT (iPhoneX ? 34.f : 0.f)
#define TAB_HEIGHT (iPhoneX ? 208.f : 153.f)
// View 坐标(x,y)和宽高(width,height)
#define X(v) (v).frame.origin.x
#define Y(v) (v).frame.origin.y
#define WIDTH(v) (v).frame.size.width
#define HEIGHT(v) (v).frame.size.height
#define MinX(v) CGRectGetMinX((v).frame)
#define MinY(v) CGRectGetMinY((v).frame)
#define MidX(v) CGRectGetMidX((v).frame)
#define MidY(v) CGRectGetMidY((v).frame)
#define MaxX(v) CGRectGetMaxX((v).frame)
#define MaxY(v) CGRectGetMaxY((v).frame)
// 加载图片
#define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
// 颜色(RGB)
#define RGBCOLOR(r, g, b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBACOLOR(r, g, b, a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
// 随机颜色
#define RANDOM_UICOLOR [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1]
///字体
#define G_FONT_TEXT(a) [UIFont systemFontOfSize:WD_ScaleFont(a)]
/**宽度比例*/
#define WD_ScaleWidth(__VA_ARGS__) ([UIScreen mainScreen].bounds.size.width/375.f)*(__VA_ARGS__)
/**高度比例*/
#define WD_ScaleHeight(__VA_ARGS__) ([UIScreen mainScreen].bounds.size.height/667.f)*(__VA_ARGS__)
/**字体比例*/
#define WD_ScaleFont(__VA_ARGS__) ([UIScreen mainScreen].bounds.size.width/375.f)*(__VA_ARGS__)
// View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]
// View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]
// alert
#define Alert(_S_, ...) [[[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:(_S_), ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil] show]
// 检查字符串是否为空
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
// 检查数组是否为空
#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
// 检查字典是否为空
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
// 检查是否是空对象
#define kObjectIsEmpty(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))
// APP对象 (单例对象)
#define kApplication [UIApplication sharedApplication]
// 主窗口 (keyWindow)
#define kKeyWindow [UIApplication sharedApplication].keyWindow
// APP对象的delegate
#define kAppDelegate [UIApplication sharedApplication].delegate
// NSUserDefaults实例化
#define kUserDefaults [NSUserDefaults standardUserDefaults]
// 通知中心 (单例对象)
#define kNotificationCenter [NSNotificationCenter defaultCenter]
// 弱引用
#define kWeakSelf(type) __weak typeof(type) weak##type = type;
// 强引用
#define kStrongSelf(type) __strong typeof(type) type = weak##type;
网友评论