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]
### Unity 常用命令和操作教程 在 Unity 中,开发者经常需要使用各种命令或操作来完成特定任务。以下是一些常用的命令和操作,涵盖了从编辑器到命令行的多个方面。 #### 1. **Unity 编辑器中的常用宏定义** 在 Unity 开发中,可以通过条件编译符号来区分不同平台的行为。以下是常见的宏定义[^4]: - `UNITY_EDITOR`:用于检测是否运行在 Unity 编辑器中。 - `UNITY_STANDALONE`:表示目标平台为独立应用(Windows、Mac 或 Linux)。 - `UNITY_ANDROID`:表示目标平台为 Android。 - `UNITY_IOS`:表示目标平台为 iOS。 - `UNITY_WEBGL`:表示目标平台为 WebGL。 示例代码: ```csharp #if UNITY_EDITOR Debug.Log("This is running in the Unity Editor."); #elif UNITY_ANDROID Debug.Log("This is running on an Android device."); #endif ``` #### 2. **命令行操作 Unity** 使用命令行可以更高效地控制 Unity 的构建过程。以下是一些常用的命令行参数[^2]: - `-batchmode`:以无界面模式运行 Unity。 - `-nographics`:禁用图形输出,通常与 `-batchmode` 一起使用。 - `-projectPath`:指定项目路径。 - `-executeMethod`:调用静态方法执行特定任务。例如: ```bash unity.exe -batchmode -nographics -projectPath "C:\MyProject" -executeMethod MyNamespace.MyClass.MyMethod ``` - `-quit`:在完成任务后自动退出 Unity。 #### 3. **ADB 调试命令** ADB(Android Debug Bridge)是调试 Android 设备的重要工具。以下是一些常用的 ADB 命令[^5]: - `adb devices`:列出所有连接的设备。 - `adb install abc.apk`:安装 APK 文件。 - `adb uninstall com.zhy.app`:卸载指定包名的应用。 - `adb logcat -s Unity`:捕获 Unity 相关的日志信息。 - `adb shell screencap /sdcard/screen.png`:截取屏幕图片。 - `adb shell screenrecord /sdcard/demo.mp4`:录制屏幕视频。 #### 4. **动画系统** Unity 提供了两种动画系统:老动画系统和 Mecanim 系统。以下是老动画系统的常用操作[^3]: - 添加 `Animation` 组件并创建动画剪辑。 - 设置播放模式(如 Once、Loop、PingPong 等)。 - 使用脚本控制动画播放: ```csharp if (Input.GetKeyDown(KeyCode.Alpha1)) { anim.Play("New Animation"); } if (Input.GetKeyDown(KeyCode.Alpha2)) { anim.Play("New Animation2"); } ``` #### 5. **设计模式——命令模式** 命令模式是一种行为型设计模式,用于将请求封装为对象,从而支持队列、日志记录和撤销等操作[^1]。以下是一个简单的实现示例: ```csharp public interface ICommand { void Execute(); } public class MoveCommand : ICommand { private Transform _transform; private Vector3 _direction; public MoveCommand(Transform transform, Vector3 direction) { _transform = transform; _direction = direction; } public void Execute() { _transform.position += _direction; } } public class CommandManager { private List<ICommand> _commands = new List<ICommand>(); public void AddCommand(ICommand command) { _commands.Add(command); } public void ExecuteAll() { foreach (var command in _commands) { command.Execute(); } } } ``` --- ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值