开发必备宏定义

笔记。

//
//  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 */
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 宏定义在很多方面都会使用,例如定义高度、判断iOS系统、工具类,还有诸如文件路径、服务端api接口文档。 ...
    我不相信me阅读 3,526评论 0 1
  • 一个小伙伴在问我自己经常用的宏定义,就记录下来,以后如果有新的再补充,目前已经很顺手了。宏是全局的,既然是全局的就...
    Ke_Wang阅读 5,443评论 4 13
  • 系统高度 快速查询一段代码的执行时间 blcok 和self 引起的循环引用警告⚠️的处理问题 代码中加入NSLo...
    GavinKang阅读 5,360评论 2 10
  • Objective-C常用宏/*! 字体 */ /*! 颜色宏定义 */ /*! 弱引用宏 */ /*! 输出显示...
    葬己阅读 4,071评论 0 0
  • mw568阅读 1,450评论 0 0

友情链接更多精彩内容