关于项目的一些细节总结-宏定义

最近项目的新需求做的差不多了,随之而来的就是短暂的空窗期,但是空窗期也不能闲着,今天现总结一下之前有关一些宏定义.

少说闲话,上点不太干的干货:

//keyWindow

#define kKeyWindow [UIApplication sharedApplication].keyWindow

//状态栏的高度

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

//导航栏的高度

#define kNavBarHeight  44.0

//iphoneX-SafeArea的高度

#define kSafeAreaHeight    ([[UIApplication sharedApplication] statusBarFrame].size.height >20?34:0)

//分栏+iphoneX-SafeArea的高度

#define kTabBarHeight  (49+ kSafeAreaHeight)

//导航栏+状态栏的高度

#define kTopHeight  (kStatusBarHeight + kNavBarHeight)

//屏幕的宽高

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

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

//屏幕大小

#define kScreenSize    [UIScreen mainScreen].bounds

#define  kTabbarSafeBottomMargin        (IS_iPhoneX ?34.f:0.f)

#define  IS_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125,2436), [[UIScreen mainScreen] currentMode].size) : NO)

//iPhoneX / iPhoneXS

#define  IS_iPhoneX_XS        (kScreenWidth ==375.f&& kScreenHeight ==812.f? YES : NO)

//iPhoneXR / iPhoneXSMax

#define  IS_iPhoneXR_XSMax    (kScreenWidth ==414.f&& kScreenHeight ==896.f? YES : NO)

//iPhoneX系列

#define IS_iPhoneX_Series    (IS_iPhoneX_XS || IS_iPhoneXR_XSMax)

// View/image 适配比例 (以375*667尺寸为基准)

#define kActureHeight(height)  roundf(height/375.0* kScreenW)

#define kActureWidth(Width)    roundf(Width/667.0* kScreenH)

//获取手机系统的版本

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

//是否为iOS8及以上系统

#define kIOS8_Later    ([[UIDevice currentDevice].systemVersion doubleValue] >=8.0)

//是否为iOS11及以上系统

#define kIOS11_Later    ([[UIDevice currentDevice].systemVersion doubleValue] >=11.0)

//沙盒路径

#define kHomePath  NSHomeDirectory()

//沙盒 Document路径

#define kPathDocument  [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

//沙盒 Cache路径

#define kPathCache  [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

//沙盒 temp路径

#define kPathTemp  NSTemporaryDirectory()

//获取视图宽高XY等信息

#define kViewH(view)    view.frame.size.height

#define kViewW(view)    view.frame.size.width

#define kViewX(view)    view.frame.origin.x

#define kViewY(view)    view.frame.origin.y

//常用系统颜色

#define kClearColor    [UIColor clearColor]

#define kWhiteColor    [UIColor whiteColor]

#define kBlackColor    [UIColor blackColor]

#define kGrayColor      [UIColor grayColor]

#define kGray2Color    [UIColor lightGrayColor]

#define kBlueColor      [UIColor blueColor]

#define kRedColor      [UIColor redColor]

//自定义RGB颜色 (a:代表透明度,1:不透明,0:透明)

#define kRGBA(r,g,b,a)  [UIColor colorWithRed:r/255.0fgreen:g/255.0fblue:b/255.0falpha:a]

//文本加粗

#define kBoldFont(FontSize)    [UIFont boldSystemFontOfSize:FontSize]

//文本字号

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

//图片付值

#define kImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]

//创建通知

#define kObserveNoti(observer, selName, notifiName)  [[NSNotificationCenter defaultCenter] addObserver:observer selector:NSSelectorFromString(selName) name:notifiName object:nil]

//发送通知

#define kNotifi(x)  [[NSNotificationCenter defaultCenter] postNotificationName:x object:nil];

//移除通知

#define kRemoveNotifi(name)  [[NSNotificationCenter defaultCenter] removeObserver:self name:name object:nil];

//信息的本地存储

#define kUserDefaults(NSUserDefaults,userDefault)  NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];

//弱化self

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

//日志打印

#ifdef DEBUG

# define NSLog(FORMAT, ...) printf("[%s<%p>行号:%d]:\n%s\n",__FUNCTION__,self,__LINE__,[[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])

#else

# define NSLog(FORMAT, ...)

#endif


如有差错,欢迎指正,另,欢迎留言丰富博文内容.感激不尽!

你可能感兴趣的:(关于项目的一些细节总结-宏定义)