iOS常用宏命令大全

第三方框架 : 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]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值