您的位置:首页 > 移动开发 > IOS开发

iOS常用宏命令大全

2016-07-14 22:00 483 查看
第三方框架 : 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]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios