IOS常用工具类宏定义

//邮箱

+ (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中定义DEBUGALogLevel, 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 关注领取手机福利



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lpstoredev

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值