自己定义的一些常用的宏

自己常用的一些宏定义 可以拿去直接用的, 自己保存记录一下

//导航

#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height

#define kNavBarHeight44.0

#define kTabBarHeight (iPhoneX?83:49)

#define kTopHeight (kStatusBarHeight + kNavBarHeight)

#define KIPhoneXSafeHeight (iPhoneX?34:0)

#define KIPhoneXBottomSafeHeight (iPhoneX?44:0)

#define KIPhoneXTotalSafeHeight (iPhoneX?78:0)

//是否为空

#define IsNilOrNull(_ref)  (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]))

//字符串是否为空

#define IsStrEmpty(_ref)    (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) ||([_ref isKindOfClass:[NSString class]] &&[(_ref)isEqualToString:@""]) || ([_ref isKindOfClass:[NSString class]] && [(_ref) isEqualToString:@"(null)"]))

//数组是否为空

#define IsArrEmpty(_ref)    (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) ||([_ref isKindOfClass:[NSArray class]]&&[(_ref) count] ==0))

//16进制色值参数转换

#define COLOR_0X(RGB) [UIColor colorWithRed:((float)((RGB &0xFF0000) >>16)) /255.0\

green:((float)((RGB &0xFF00) >>8)) /255.0\

blue:((float)((RGB &0xFF))) /255.0\

alpha:1.0]

//RGB颜色转换

#define RGBA(r,g,b,p) [UIColor colorWithRed:(CGFloat)(r)/255.0green:(CGFloat)(g)/255.0blue:(CGFloat)(b)/255.0alpha:p]

//单例创建

#undef AS_SINGLETON

#define AS_SINGLETON( __class ) \

+ (__class *)sharedInstance;

#undef DEF_SINGLETON

#define DEF_SINGLETON( __class ) \

+ (__class *)sharedInstance \

{ \

static dispatch_once_t once; \

static __class * __singleton__; \

dispatch_once( &once, ^{ __singleton__ = [[__class alloc] init]; } ); \

return __singleton__; \

}

// 随机色

#define YKRandomColor YKColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))

// 透明颜色

#define YKAlphaColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0green:(g)/255.0blue:(b)/255.0alpha:(a)/10.0]

//提示框

#define ShowMessage(TITLE,MESSAGE,QUVC) UIAlertController *alertController = [UIAlertController alertControllerWithTitle:TITLE message:MESSAGE preferredStyle:UIAlertControllerStyleAlert];\

[alertController addAction:[UIAlertAction actionWithTitle:@"确定"style:UIAlertActionStyleDefault handler:nil]];\

[QUVC presentViewController:alertController animated:YES completion:nil];

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。