pch文件常用的宏

//

//  Constants.h

//  FitnessTest

//

//  Created by hubing on 15/9/18.

//  Copyright (c) 2015 hubing. All rights reserved.

//


#ifndef FitnessTest_Constants_h

#define FitnessTest_Constants_h



//系统版本

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


//判断系统

#define IsIOS6 (([[[UIDevice currentDevice] systemVersion] floatValue] >=6.0 &&[[[UIDevice currentDevice] systemVersion] floatValue] <7.0) ? YES : NO)

#define IsIOS7 (([[[UIDevice currentDevice] systemVersion] floatValue] >=7.0 &&[[[UIDevice currentDevice] systemVersion] floatValue] <8.0) ? YES : NO)

#define IsIOS8 (([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0 &&[[[UIDevice currentDevice] systemVersion] floatValue] <9.0) ? YES : NO)



//计算颜色

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

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



//主题色

#define COMMON_COLOR [UIColor colorWithRed:0xeb/255.0 green:0x61/255.0 blue:0x00/255.0 alpha:1.0]


//相对高度

#define kLeft(VIEW)                 VIEW.frame.origin.x

#define kUp(VIEW)                   VIEW.frame.origin.y

#define kRight(VIEW)                (kLeft(VIEW) + VIEW.frame.size.width)

#define kWidth(VIEW)                VIEW.frame.size.width

#define kHeight(VIEW)               VIEW.frame.size.height

#define kDown(VIEW)                 (VIEW.frame.origin.y + VIEW.frame.size.height)


//打印相关

#ifdef DEBUG

#define DLog( s, ... )                          NSLog( @"<%@:(%d)> %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )

#else

#define DLog( s, ... )

#endif



//屏幕尺寸

#define SCREENFRAME [[UIScreen mainScreen] bounds]  // 当前屏幕frmae

#define SCREENWIDTH SCREENFRAME.size.width          // 当前屏幕宽度

#define SCREENHEIGHT SCREENFRAME.size.height        // 当前屏幕高度

#define SCREEN_MAX_LENGTH (MAX(SCREENWIDTH, SCREENHEIGHT))

#define SCREEN_MIN_LENGTH (MIN(SCREENWIDTH, SCREENHEIGHT))


//#define H(X) ((SCREENFRAME.size.height) * ((X) / 667.0))    // 适配屏幕高度(以667为基准iphone6

//#define W(X) ((SCREENFRAME.size.width) * ((X) / 375.0))     // 适配屏幕宽度(以375为基准iphone6


#define H(X) ((SCREENFRAME.size.height) * ((X) / 736.0))    // 适配屏幕高度(以736为基准iphone6p

#define W(X) ((SCREENFRAME.size.width) * ((X) / 414.0))     // 适配屏幕宽度(以414为基准iphone6p



//判断是否是iPhone

#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)


//判断是否是4

#define IS_IPHONE_4_OR_LESS (IS_IPHONE && SCREEN_MAX_LENGTH < 568.0)

//判断是否是5

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

//判断是否是6

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

//判断是否是6P

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



//状态栏高度

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


// View 圆角和加边框

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

\

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

[View.layer setMasksToBounds:YES];\

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

[View.layer setBorderColor:[Color CGColor]]



//字符串是否为空

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


//数组是否为空

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


//button点击事件

#define kAddEventDefault(OBJ,SELECTOR)  [OBJ addTarget:self action:@selector(SELECTOR) forControlEvents:UIControlEventTouchUpInside]


//PushPop

#define kPopViewController          [self.navigationController popViewControllerAnimated:YES]

#define kPushViewController(VC)     [self.navigationController pushViewController:VC animated:YES]



//Label自适应宽高

#define LabelSize(label,W,H) [label.text boundingRectWithSize:CGSizeMake(W,H) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName: label.font} context:nil].size



//String自适应宽高

#define StringSize(String,W,H,Font) [String boundingRectWithSize:CGSizeMake(W,H) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin |NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:Font]} context:nil].size


#define setBoolForKey(bool,key) [[NSUserDefaults standardUserDefaults] setBool:bool forKey:key]

#define boolForKey(key) [[NSUserDefaults standardUserDefaults] boolForKey:key]


#define kFont(float) [UIFont systemFontOfSize:float]


#endif


你可能感兴趣的:(iOS)