开发必备宏定义

2017-11-24  本文已影响11人  wahkim

笔记。

//
//  LHQPch.pch
//  LHQProgressHUD
//
//  Created by Hq.Lin on 2017/11/23.
//  Copyright © 2017年 lin. All rights reserved.
//

#ifndef LHQPch_pch
#define LHQPch_pch

//获取屏幕宽高
#define LHQSCREEN_W [[UIScreen mainScreen]bounds].size.width
#define LHQSCREEN_H [[UIScreen mainScreen]bounds].size.height
#define LHQSCREEN_BOUNDS [UIScreen mainScreen].bounds
#define LHQSCREEN_BOUNDS_SIZE [UIScreen mainScreen].bounds.size

//状态栏高度
#define LHQStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height//iphoneX 高44pt 其他20pt
//导航栏高度
#define LHQNavBarHeight 44.0
//tabBar高度
#define LHQTabBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height>20?83:49)//iphoneX 底部高34pt (+49pt = 83pt)
//导航栏高度 + 状态栏高度
#define LHQTopHeight (LHQStatusBarHeight + LHQNavBarHeight)

//不同屏幕尺寸字体适配
#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_PAD (UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPad)
#define KStandardW (IS_IPHONE ? 375 : 768)
#define KStandardH (IS_IPHONE ? 667 : 1024)

#define kScreenWidthRatio  (UIScreen.mainScreen.bounds.size.width / KStandardW)
#define kScreenHeightRatio (UIScreen.mainScreen.bounds.size.height / KStandardH)
#define AdaptedWidth(x)  ceilf((x) * kScreenWidthRatio)
#define AdaptedHeight(x) ceilf((x) * kScreenHeightRatio)
#define AdaptedFontSize(R)     [UIFont systemFontOfSize:AdaptedWidth(R)]

//强弱引用
#define LHQWeakSelf(type)__weak typeof(type)weak##type = type;
#define LHQStrongSelf(type)__strong typeof(type)type = weak##type;

//DEBUG模式下打印日志,当前行
#ifdef DEBUG
#define DLog(fmt,...)NSLog((@"%s[Line %d]" fmt),__PRETTY_FUNCTION__,__LINE__,##__VA_ARGS__);
#else
#define DLog(...)
#endif

//定义UIImage对象
#define ImageWithFile(_pointer) [UIImage imageWithContentsOfFile:([[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"%@@%dx",_pointer,(int)[UIScreen mainScreen].nativeScale]ofType:@"png"])]
#define IMAGE_NAMED(name)       [UIImage imageNamed:name]

//字体
#define BOLDSYSTEMFONT(FONTSIZE)    [UIFont boldSystemFontOfSize:FONTSIZE]
#define SYSTEMFONT(FONTSIZE)        [UIFont systemFontOfSize:FONTSIZE]
#define FONT(NAME,FONTSIZE)         [UIFont fontWithName:(NAME)size:(FONTSIZE)]
//方正黑体简体字体定义
#define FONT_ISNAME(F)              [UIFont fontWithName:@"FZHTJW--GB1-0" size:F]

//颜色
// 随机色 透明度
#define LHQRandomColorWithAlpha(a)      [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:(a)]
// 自定义颜色 透明度
#define LHQColorWithAlpha(r, g, b, a)   [UIColor colorWithRed:(r) / 255.0 green:(g) / 255.0 blue:(b) / 255.0 alpha:a]
//16进制颜色
#define COLOR_WITH_HEX(hexValue)        [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16)) / 255.0 green:((float)((hexValue & 0xFF00) >> 8)) / 255.0 blue:((float)(hexValue & 0xFF)) / 255.0 alpha:1.0f]

//NSUserDefaults 实例化
#define UserDefaults  [NSUserDefaults standardUserDefaults]

#endif /* LHQPch_pch */
上一篇 下一篇

猜你喜欢

热点阅读