iOS-常用宏定义

自己常用宏定义

/*

 打印信息

 */

#ifdef DEBUG

#define BRYLog( s, ... ) printf("class: <%p %s:(%d) > method: %s \n%s\n", self, [[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, __PRETTY_FUNCTION__, [[NSString stringWithFormat:(s), ##__VA_ARGS__] UTF8String] )

#else

#define BRYLog( s, ... )

#endif

/*

 弱指针

 */

#define BRYWeakType(type) __weak typeof(type) weak##type = type

#define BRYWeakSelf typeof(self) __weak weakSelf = self;

#define BRYStrongSelf typeof(self) __strong self = weakSelf;

/*

 懒加载

 */

#define LazyLoadArray(obj)\

-(NSMutableArray *)obj{\

if (_##obj == nil) {\

_##obj = [[NSMutableArray alloc]init];\

}\

return _##obj;\

}

#define LazyLoadDict(obj)\

-(NSMutableDictionary *)obj{\

if (_##obj == nil) {\

_##obj = [[NSMutableDictionary alloc]init];\

}\

return _##obj;\

}

/*

 键盘类型

 */

#define NUM @"0123456789"

#define ALPHA @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

#define ALPHANUM @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"

/*

 判断是否为空

 */

#define BRYNullString(str) ([str isKindOfClass:[NSNull class]] || str == nil || ([str length] <1) ? (YES) : (NO))//字符串是否为空

#define BRYNullArray(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count ==0)//数组是否为空

#define BRYNullDictionary(dictionary) (dictionary == nil || [dictionary isKindOfClass:[NSNull class]] || dictionary.allKeys ==0)//字典是否为空

#define BRYNullObject(_object) (_object == nil \

|| [_object isKindOfClass:[NSNull class]] \

|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] ==0) \

|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] ==0))/** 是否是空对象*/

/*

 字体

 */

#define BRYFont(S)                [UIFont systemFontOfSize:S]

/*

 颜色

 */

#define BRYRGBColor(r, g, b)      [UIColor colorWithRed:(r)/255.0green:(g)/255.0blue:(b)/255.0alpha:1.0]

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

#define BRYSuoJiColor [UIColor colorWithRed:arc4random_uniform(256)/255.0green:arc4random_uniform(256)/255.0blue:arc4random_uniform(256)/255.0alpha:1.0]//随机颜色

#define BRYThemeColor            BRYRGBColor(47,115,245)//项目主题色

#define BRYLineViewColor          BRYRGBColor(200,200,200)//细线背景色

#define BRYTextColor              BRYRGBColor(51,51,51)//文本颜色

#define BRYVCBackColor            BRYRGBColor(246,246,246)//VC背景色

#define BRYGrayColor              BRYRGBColor(238,238,238)//浅灰色

/*

 圆角、边框、颜色

 */

#define FBViewBorderRadius(View, Radius, Width, Color)\

\

[View.layer setCornerRadius:(Radius)];\

[View.layer setMasksToBounds:YES];\

[View.layer setBorderWidth:(Width)];\

[View.layer setBorderColor:[Color CGColor]]

//切角

#define FBViewRadius(View, Radius)\

\

[View.layer setCornerRadius:(Radius)];\

[View.layer setMasksToBounds:YES]

//图片平铺

#define FBViewContentMode(Image, Mode)\

\

[Image setContentMode:Mode];\

[Image setClipsToBounds:YES]

/*

 屏幕

 */

//屏幕尺寸相关、状态栏高度

#define BRYScreenWidht          [UIScreen mainScreen].bounds.size.width

#define BRYScreenHeight          [UIScreen mainScreen].bounds.size.height

#define BRYScreenStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height//状态栏高度

#define BRYTabBarHeight self.tabBarController.tabBar.bounds.size.height

#define BRYIsIPhoneX ([[UIApplication sharedApplication] statusBarFrame].size.height>20?YES:NO)

#define BRYIPhoneTabBarH (FBScreenStatusBarHeight>20?34:0)//获取底部黑线区域针对iPhoneX

#define BRYDevice_OS_Version [[[UIDevice currentDevice] systemVersion] floatValue]

/*

 提示信息

 */

#define BRYShowLoading(Text)      [LCProgressHUD showLoading:Text];//加载中

#define BRYShowMessage(Text)      [LCProgressHUD showMessage:Text];//只有文字提示

#define BRYShowHid                [LCProgressHUD hide];//隐藏提示框

//#define BRYShowSuccess(Text)      [LCProgressHUD showSuccess:Text];//加载成功

//#define BRYShowInfoMsg(Text)      [LCProgressHUD showInfoMsg:Text];///提示信息

//#define BRYShowFailure(Text)      [LCProgressHUD showFailure:Text];//加载失败

/*

 通知和UserDefaults

 */

#define BRYNSUserDefaults        [NSUserDefaults standardUserDefaults]

#define BRYNSNotification        [NSNotificationCenter defaultCenter]

你可能感兴趣的:(iOS-常用宏定义)