OC 基本宏定义

//

//  JWCommon.h

//  jiawo

//

//  Created by Yin Yi on 15/10/10.

//  Copyright © 2015年 ZHE JIANG ASUN PROPERTY MANAGEMENT. All rights reserved.

//  全局宏

#ifndef JWCommon_h

#define JWCommon_h

// 版本

#define JWDeviceVersion [[UIDevice currentDevice].systemVersion doubleValue]

// rgb颜色

//全局Color Helper

#define HEXCOLORA(rgbValue, a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 blue:((float)(rgbValue & 0xFF)) / 255.0 alpha:a]

#define HEXCOLOR(rgbValue) HEXCOLORA(rgbValue, 1.0)

#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 RGBA(r,g,b,a) (r)/255.0f, (g)/255.0f, (b)/255.0f, (a)

// 当前屏幕尺寸

#define     BOUNDS              [[UIScreen mainScreen] bounds]

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

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

#define     HEIGHT_64           ([[UIScreen mainScreen] bounds].size.height - 64)

#define     BOUNDS_64            (CGRectMake(0,0,WIDTH,HEIGHT_64))

// 屏幕尺寸

#define JWScreemSize [UIScreen mainScreen].bounds.size

#define JWRectMake(x,y,w,h) CGRectMake(JWScreemSize.width * ((x) / 375.0), JWScreemSize.height * ((y) / 667.0), JWScreemSize.width * ((w) / 375.0), JWScreemSize.height * ((h) / 667.0))

#define JWScaleX(x) JWScreemSize.width * ((x) / 375.0)

#define JWScaleY(y) JWScreemSize.height * ((y) / 667.0)

//判断手机型号

#define SCREEN_WIDTH ([[UIScreen mainScreen] bounds].size.width)

#define SCREEN_HEIGHT ([[UIScreen mainScreen] bounds].size.height)

#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

#define SCREEN_MAX_LENGTH (MAX(SCREEN_WIDTH, SCREEN_HEIGHT))

#define IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)

#define IPHONE_5 (IS_IPHONE && SCREEN_MAX_LENGTH == 568.0)

#define IPHONE_6 (IS_IPHONE && SCREEN_MAX_LENGTH == 667.0)

#define IPHONE_6P (IS_IPHONE && SCREEN_MAX_LENGTH == 736.0)

// 设备系统版本 > 7.0

#define IOS_VERSION_7_OR_ABOVE  ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)

#define IOS_VERSION_8_OR_ABOVE  ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)

#define IOS_VERSION_9_OR_ABOVE  ([[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0)

//#define JWScaleW JWScreemSize.width / 375.0

//#define JWScaleH JWScreemSize.height / 667.0

//6P 上的文字设置比6以及6以下尺寸上的文字大一号

#define FontFromIphone(_X_)  IPHONE_6P ? [UIFont systemFontOfSize:_X_+1] : [UIFont systemFontOfSize:_X_]

//#define FontFromIphone(_X_)  IPHONE_6P ? [UIFont systemFontOfSize:_X_+1] : [UIFont systemFontOfSize:_X_]

#define FontFromIphoneSize(_X_)  IPHONE_6P ? (_X_+1) : (_X_)

//固定font 无论在何种iPhone上

#define FontOfInt(_X_) [UIFont systemFontOfSize:_X_]

//NSNull 转 @""

#define checkNull(__X__)        (__X__) == [NSNull null] || (__X__) == nil ? @"" : [NSString stringWithFormat:@"%@", (__X__)]

#define alert(__TITLE__) if (JWDeviceVersion >= 8.0) { \

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:__TITLE__ preferredStyle:UIAlertControllerStyleAlert];\

[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil]; \

double delay = 1; \

dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delay *NSEC_PER_SEC); \

dispatch_after(popTime, dispatch_get_main_queue(), ^{ \

    [alertController dismissViewControllerAnimated:YES completion:nil]; \

}); \

} else { \

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:__TITLE__ delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil]; \

    [alert show]; \

}

// 图片缓存路径

#undef DEF_IMAGESCHEPATH

#define DEF_IMAGESCHEPATH [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]

// 单例

#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__; \

}

// 调试时候的输出方法

#ifdef DEBUG

#define JWLog(...) NSLog(__VA_ARGS__)

#else

#define JWLog(...)

#endif

/********普通打印描述(依赖DEBUG开关)********/

#ifdef DEBUG

#define PRINT_STRING(NSString) if (DEBUG) NSLog(@"%@",NSString)

#else

#define PRINT_STRING(NSString)

#endif

#define kNetWorkingTimeoutInterval 20

//共用颜色

#define CommonLightGray HEXCOLOR(0x999999);

#endif /* JWCommon_h */

#define JW15FONT [UIFont systemFontOfSize:15]

#define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self

猜你喜欢

转载自my.oschina.net/u/2287505/blog/1632156