//邮箱
+ (BOOL) validateEmail:(NSString *)email
{
NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:email];
}
//判断是否为模拟器
+(BOOL)DeviceIsSimulator
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *tmpDevStr = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
if ([tmpDevStr isEqualToString:@"x86_64"]
|| [tmpDevStr isEqualToString:@"i386"]
|| [tmpDevStr isEqualToString:@"i586"]) {
return YES;
}
return NO;
}
/**
* RGB颜色
*
*/
#define LHRGBColor(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:1.0]
/**
* 随机颜色测试用
*
*/
#define LHRandomColor LHRGBColor(arc4random_uniform(256),arc4random_uniform(256),arc4random_uniform(256))
/**
* RGB或者16进制颜色
*/
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
/**
* RGB或者16进制颜色,可选alpha值
*/
#define UIColorFromRGBHalfAlpha(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:0.5]
//NavBar高度
#define NavigationBar_HEIGHT 44
//获取屏幕 宽度、高度
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)
//获取系统版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]
#define CurrentPhoneModel [[UIDevice currentDevice] model]
//适配
#define SM_size_height(P) P*([UIScreen mainScreen].bounds.size.height/667)
#define SM_size_width(P) P*([UIScreen mainScreen].bounds.size.width/375)
/*
终端调试日志的宏定义
1. 去掉定义DEBUG,可关闭日志
2. 定义ALogLevel修改日志等级
使用:
1. 在xxx-Prefix.pch中定义DEBUG和ALogLevel, 并import本文件
2. 使用示例:
ALogVerbose(@"msg=%@ number=%d", @"info", 123);
*/
// 日志等级常量
#define ALOG_LEVEL_DEBUG 9 // 调试
#define ALOG_LEVEL_INFO 7 // 提示
#define ALOG_LEVEL_WARNING 5 // 警告
#define ALOG_LEVEL_ERROR 3 // 出错
// 日志等级
#ifndef ALogLevel
#define ALogLevel ALOG_LEVEL_DEBUG // 初始值
#endif
// 输出定义
#ifdef DEBUG
#define ALOG_PRINT(xx, yy, ...) NSLog(@"[%@]%s(%d):" xx, yy, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define ALOG_PRINT(xx, yy, ...) ((void)0)
#endif
// 调试日志函数
#if ALOG_LEVEL_VERBOSE <= ALogLevel
#define ALogDebug(xx, ...) ALOG_PRINT(xx, @"debug", ##__VA_ARGS__)
#define ALogVerbose(xx, ...) ALOG_PRINT(xx, @"debug", ##__VA_ARGS__)
#else
#define ALogDebug(xx, ...) ((void)0)
#define ALogVerbose(xx, ...) ((void)0)
#endif
// 提示日志函数
#if ALOG_LEVEL_INFO <= ALogLevel
#define ALogInfo(xx, ...) ALOG_PRINT(xx, @"info ", ##__VA_ARGS__)
#else
#define ALogInfo(xx, ...) ((void)0)
#endif
// 警告日志函数
#if ALOG_LEVEL_WARNING <= ALogLevel
#define ALogWarn(xx, ...) ALOG_PRINT(xx, @"warn ", ##__VA_ARGS__)
#else
#define ALogWarn(xx, ...) ((void)0)
#endif
// 出错日志函数
#if ALOG_LEVEL_ERROR <= ALogLevel
#define ALogError(xx, ...) ALOG_PRINT(xx, @"error", ##__VA_ARGS__)
#else
#define ALogError(xx, ...) ((void)0)
#endif
加微信 appshi6 关注领取手机福利