iOS----------常见宏定义
在我们日常的项目中,合理的使用宏定义,会大大减少我们的代码量,以及代码的可读性,为方便读者使用,总结如下:
pragma mark - Application相关
///=============================================================================
/// @name Application
///=============================================================================
#define APPLICATION [UIApplication sharedApplication]
#define APPDLE (AppDelegate*)[APPLICATION delegate]
#define kKeyWindow [UIApplication sharedApplication].keyWindow
#define kUserDefaults [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]
//获取temp
#define kPathTemp NSTemporaryDirectory()
//获取沙盒 Document
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//获取沙盒 Cache
#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
///=============================================================================
pragma mark - Frame相关
///=============================================================================
/// @name Frame相关
///=============================================================================
// 控件尺寸比例
#define kScreenRate (kScreenWidth/375.f)
// 实际尺寸
#define kSuitSize(size) kScreenRate * (size)
///=============================================================================
pragma mark - 屏幕坐标、尺寸相关
///=============================================================================
/// @name 屏幕坐标、尺寸相关
///=============================================================================
//判断是否iPhone X
#define IS_iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
// 屏幕高度
#define kScreenHeight [[UIScreen mainScreen] bounds].size.height
// 屏幕宽度
#define kScreenWidth [[UIScreen mainScreen] bounds].size.width
// 状态栏高度
#define kStatusBarHeight (IS_iPhoneX ? 44.f : 20.f)
// 顶部导航栏高度
#define kNavigationBarHeight 44.f
// 顶部安全距离
#define kSafeAreaTopHeight (IS_iPhoneX ? 88.f : 64.f)
// 底部安全距离
#define kSafeAreaBottomHeight (IS_iPhoneX ? 34.f : 0.f)
// Tabbar高度
#define kTabbarHeight 49.f
// 去除上下导航栏剩余中间视图高度
#define ContentHeight (kScreenHeight - kSafeAreaTopHeight - kSafeAreaBottomHeight - kTabbarHeight)
///=============================================================================
pragma mark - 系统相关
///=============================================================================
/// @name 系统相关
///=============================================================================
// app版本号
#define DEVICE_APP_VERSION (NSString *)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]
// app Build版本号
#define DEVICE_APP_BUILD (NSString *)[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"]
// 系统版本号(string)
#define DEVICE_OS_VERSION [[UIDevice currentDevice] systemVersion]
// 系统版本号(float)
#define DEVICE_OS_VERSION_VALUE [DEVICE_OS_VERSION floatValue]
///=============================================================================
pragma mark - 字体、颜色相关
///=============================================================================
/// @name 字体、颜色相关
///=============================================================================
#define FONT_SIZE(f) [UIFont systemFontOfSize:(f)]
#define FONT_BOLD_SIZE(f) [UIFont boldSystemFontOfSize:(f)]
#define FONT_ITALIC_SIZE(f) [UIFont italicSystemFontOfSize:(f)]
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.f green:(g)/255.f blue:(b)/255.f alpha:1.f]
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.f green:(g)/255.f blue:(b)/255.f alpha:(a)]
#define RandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
#define ColorWithHex(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16)) / 255.0 green:((float)((rgbValue & 0xFF00) >> 8)) / 255.0 blue:((float)(rgbValue & 0xFF)) / 255.0 alpha:1.0]
///=============================================================================
pragma mark - NSLog相关
///=============================================================================
/// @name NSLog相关
///=============================================================================
#ifdef DEBUG
#define MLLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define NSLog(...)
#endif
///=============================================================================
pragma mark - 判断数据是否为空
///=============================================================================
/// @name 判断数据是否为空
///=============================================================================
#define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
#define kArrayIsEmpty(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
#define kDictIsEmpty(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
///=============================================================================
iOS----------常见宏定义的更多相关文章
- iOS 使用宏定义函数和代码块
iOS使用宏定义函数和代码块 今天在开发过程中碰到一个问题:就是父类中要向外发送通知,然后子类中或者其他类中来接收它.当然一般是把它写到类方法中去,但是有个问题,就是如果调用的类不是它的子类,就不能直 ...
- iOS常用宏 定义
总结了iOS开发过程中的一些常用宏,以后会陆陆续续添加进来. 字符串是否为空 1 #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull c ...
- iOS重用宏定义
iOS 多快好省的宏(转) 原文地址:http://my.oschina.net/yongbin45/blog/150149 // 字符串: #ifndef nilToEmpty #define ni ...
- iOS常用宏定义--实用
在这里给大家分享一些常用的宏定义,喜欢的小伙伴可以直接在项目中使用(持续更新)!为了大家使用方便,请点击GitHub - 宏定义头文件下载 ! 1.获取屏幕宽度与高度 #define SCREEN_W ...
- iOS常用宏定义大全
宏定义与常量的区别 宏:只是在预处理器里进行文本替换,不做任何类型检查,宏能定义代码,const不能,多个宏编译时间相对较长,影响开发效率,调试过慢,const只会编译一次,缩短编译时间. 所以在使用 ...
- iOS之宏定义#define
最基本的宏定义用法 #define aaa bbb 表示用aaa替换bbb的内容. 宏作用范围 宏的作用范围是在当前文件内, 如果需要作用于其他类(如在类b调用类a已定义宏),那么需要在类b引入类a的 ...
- iOS常用宏定义
转发:https://www.douban.com/note/486674206/ #ifndef MacroDefinition_h#define MacroDefinition_h //----- ...
- 【编程基础】C语言常见宏定义
我们在使用C语言编写程序的时候,常常会使用到宏定义以及宏编译指令,有的可能比较常用,有的可能并不是很常用,是不是所有的C语言宏定义以及宏指令你都清楚呢? 指令 用途详细介绍 # 空指令,无任何效果 # ...
- iOS define 宏定义 和 const定义常量区别
const const 是c++中的修饰符. c++中常用来定义常量,修饰左值. #define 宏定义语句, 在预处理阶段直接做文本替换,不做类型检查. 它们之间的最大区别: 1. 对于co ...
- (转)iOS 常用宏定义
#ifndef MacroDefinition_h #define MacroDefinition_h //-------------------获取设备大小------------------- ...
随机推荐
- Gem::LoadError: Specified 'sqlite3' for database adapter, but the gem is not loaded
解决办法: 指定sqlite3的版本为1.3.13: gem 'sqlite3', '~> 1.3.13' 然后运行bundle update
- Redis结合Lua脚本实现高并发原子性操作
从 2.6版本 起, Redis 开始支持 Lua 脚本 让开发者自己扩展 Redis … 案例-实现访问频率限制: 实现访问者 $ip 在一定的时间 $time 内只能访问 $limit 次. 非脚 ...
- [Swift]LeetCode729. 我的日程安排表 I | My Calendar I
Implement a MyCalendar class to store your events. A new event can be added if adding the event will ...
- [Swift]LeetCode890. 查找和替换模式 | Find and Replace Pattern
You have a list of words and a pattern, and you want to know which words in words matches the patter ...
- js 里面的键盘事件对应的键码
js 里面的键盘事件经常用到,所以收集了键盘事件对应的键码来分享下:keyCode 8 = BackSpace BackSpacekeyCode 9 = Tab TabkeyCode 12 = Cle ...
- VirtualBox虚拟机克隆迁移步骤
VirtualBox是常用的虚拟机管理软件,和VMware一样,用的很多.在使用过程中,有的时候需要对虚拟机进行迁移.比如我们原来的服务器,使用的win10操作系统,上面利用VirtualBox安装了 ...
- 【机器学习】--线性回归中soft-max从初始到应用
一.前述 Soft-Max是做多分类的,本身是哪个类别的概率大,结果就为对应的类别.为什么称之为Soft判别,原因是归一化之后的概率选择最大的作为结果,而不是只根据分子. 二.原理 sigmod函数: ...
- 机器学习 GBDT+xgboost 决策树提升
目录 xgboost CART(Classify and Regression Tree) GBDT(Gradient Boosting Desicion Tree) GB思想(Gradient Bo ...
- 10.Django ModelForm
ModelForm 1.ModeForm简单验证 from django.db import models # Create your models here. class UserInfo(mode ...
- 如何判断DataSet里有多少个DataTable
dataset.table.count sda.fill(ds,"table"); //这里是在ds里新建了一个表,叫table,注意是新建,多次执行会报错,实际使用时,可以用co ...