iOS常用宏命令大全
2016-07-14 22:00
483 查看
第三方框架 : Masonry 省略前缀 ‘mas_’
屏幕左右留间距
判断手机是否是 iPhone5,返回值是 BOOL值
判断手机是否是 iPhone6,返回值是 BOOL值
判断手机是否是 iPhone6Plus,返回值是 BOOL值
定义若指针 self
获取AppDelegate
用户偏好对象
获取屏幕宽高
颜色常用的宏命令
快速设置字体
打印 frame
打印一个点
Xcode 的一些配置
获取系统版本号
快速获取沙河路径
//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]
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 简单讲解C语言中宏的定义与使用
- C/C++ 宏详细解析
- 深入探讨:宏、内联函数与普通函数的区别
- C++十六进制宏的用法详解
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用开发中AFNetworking库的常用HTTP操作方法小结
- iOS应用中UISearchDisplayController搜索效果的用法
- iOS App开发中的UISegmentedControl分段组件用法总结
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- iOS中UIAlertView警告框组件的使用教程