博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS常用宏命令大全
阅读量:4047 次
发布时间:2019-05-24

本文共 4043 字,大约阅读时间需要 13 分钟。

第三方框架 : Masonry 省略前缀 ‘mas_’

//define this constant if you want to use Masonry without the 'mas_' prefix#define MAS_SHORTHAND//define this constant if you want to enable auto-boxing for default syntax#define MAS_SHORTHAND_GLOBALS// 导入头文件#import "Masonry.h"

屏幕左右留间距

#define kLeftOffsetPadding (SCREEN_WIDTH*0.2)

判断手机是否是 iPhone5,返回值是 BOOL值

#define kDevice_Is_iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

判断手机是否是 iPhone6,返回值是 BOOL值

#define kDevice_Is_iPhone6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)

判断手机是否是 iPhone6Plus,返回值是 BOOL值

#define kDevice_Is_iPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)

定义若指针 self

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

获取AppDelegate

#define STAppDelegate  (AppDelegate *)[UIApplication sharedApplication].delegate

用户偏好对象

#define STDefaults (NSUserDefaults *)[NSUserDefaults standardUserDefaults]

获取屏幕宽高

#define SCREEN_LEFT_WIDTH ([UIScreen mainScreen].bounds.size.width*0.8)#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)#define kProportion   SCREEN_WIDTH/320 // 5 ok#define kProportion6  SCREEN_WIDTH/375#define kProportion6P SCREEN_WIDTH/414

颜色常用的宏命令

// 随机色#define RANDOMCOLOR [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1]#define RGBCOLOR(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]#define RGBHexColor(hexValue) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16)) / 255.0 green:((float)((hexValue & 0xFF00) >> 8)) / 255.0 blue:((float)(hexValue & 0xFF)) / 255.0 alpha:1.0] //RGBHexColor(0xefefef)// 一些常用颜色#define CLEAR_COLOR [UIColor clearColor]#define DEEPBLUE_COLOR RGBHexColor(0x44b2f0)#define BLUE_COLOR RGBHexColor(0x23a7f1)#define WHITE_COLOR RGBHexColor(0xffffff)#define LIGHTBLUE_COLOR RGBHexColor(0xa8c7e0)#define GRAY_COLOR RGBHexColor(0xf6f8fa)#define ORANGE_COLOR RGBHexColor(0xf39800)#define RED_COLOR RGBHexColor(0xf0311d)#define DEEPBLACK_COLOR RGBHexColor(0x252525)#define LIGHTBLACK_COLOR RGBHexColor(0x333333)#define LIGHTBLACK_COLOR666 RGBHexColor(0x666666)#define LIGHTBLACK_COLOR999 RGBHexColor(0x999999)

快速设置字体

#define BOLDFONT(F) [UIFont boldSystemFontOfSize:F]#define FONT(F)     [UIFont systemFontOfSize:F]

打印 frame

#define LogFrame(frame) loggerImpt(@"frame[X=%.1f,Y=%.1f,W=%.1f,H=%.1f",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height);

打印一个点

#define LogPoint(point) loggerImpt(@"Point[X=%.1f,Y=%.1f]",point.x,point.y);

Xcode 的一些配置

#define XCODE_COLORS_ESCAPE @"\033["#define XCODE_COLORS_RESET_FG XCODE_COLORS_ESCAPE @"fg;" // Clear any foreground color#define XCODE_COLORS_RESET_BG XCODE_COLORS_ESCAPE @"bg;" // Clear any background color#define XCODE_COLORS_RESET XCODE_COLORS_ESCAPE @";" // Clear any foreground or background color///黑色 正常信息#define loggerInfo(frmt, ...) NSLog((XCODE_COLORS_ESCAPE @"fg0,0,0;" frmt XCODE_COLORS_RESET), ##__VA_ARGS__);///蓝色 重要信息#define loggerImpt(frmt, ...) NSLog((XCODE_COLORS_ESCAPE @"fg0,0,255;" frmt XCODE_COLORS_RESET), ##__VA_ARGS__);///橙色 警告信息#define loggerWarn(frmt, ...) NSLog((XCODE_COLORS_ESCAPE @"fg255,127,0;" frmt XCODE_COLORS_RESET), ##__VA_ARGS__);///红色 错误信息#define loggerError(frmt, ...) NSLog((XCODE_COLORS_ESCAPE @"fg255,0,0;" @"(%d)"  frmt XCODE_COLORS_RESET),__LINE__, ##__VA_ARGS__);

获取系统版本号

#define iOS_SYSTEM   [[[UIDevice currentDevice] systemName] doubleValue]

快速获取沙河路径

// 获取其他文件夹路径只要修改一下参数即可#define kFilePath(fileName) [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject] stringByAppendingPathComponent:fileName]

转载地址:http://tfwci.baihongyu.com/

你可能感兴趣的文章
autohotkey快捷键显示隐藏文件和文件扩展名
查看>>
Linux中的进程
查看>>
学习python(1)——环境与常识
查看>>
学习设计模式(3)——单例模式和类的成员函数中的静态变量的作用域
查看>>
自然计算时间复杂度杂谈
查看>>
当前主要目标和工作
查看>>
使用 Springboot 对 Kettle 进行调度开发
查看>>
一文看清HBase的使用场景
查看>>
解析zookeeper的工作流程
查看>>
搞定Java面试中的数据结构问题
查看>>
慢慢欣赏linux make uImage流程
查看>>
linux内核学习(7)脱胎换骨解压缩的内核
查看>>
以太网基础知识
查看>>
慢慢欣赏linux 内核模块引用
查看>>
kprobe学习
查看>>
慢慢欣赏linux phy驱动初始化2
查看>>
慢慢欣赏linux CPU占用率学习
查看>>
2020年终总结
查看>>
Homebrew指令集
查看>>
React Native(一):搭建开发环境、出Hello World
查看>>