iOS 开发中常用的宏定义

作者: 胡胡LoL | 来源:发表于2017-05-25 17:05 被阅读38次

iOS 开发中常用的一些宏定义

1.关于设置颜色

//设置颜色
①.常见的方式
#define HHGlobalBackgroundColor [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1.0]

#define HHCommonColor [UIColor colorWithRed:152/255.0 green:158/255.0 blue:0/255.0 alpha:1.0]  
②.书写方便的宏
#define HHColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

③.16进制RGB的颜色转换 --->推荐使用
#define HHColorFromHex(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
使用时直接调用宏定义:后面直接传入 `0x(0~f)`
例如:[dateLabel setTextColor:ZNColorFromHex(0x989e00)];

④.随机色
#define HHRandomColor JYJColor(arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))

2.自定义 Log

#ifdef DEBUG
#define HHLog(...) NSLog(__VA_ARGS__)
#else
#define HHLog(...)
#endif
#define HHLogFunc HHLog(@"%s",__func__);  

//重写HHNSLog,Debug模式下打印日志和当前行数
#if DEBUG
#define HHNSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define HHNSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#endif

3.弱引用

#define HHWeakSelf __weak typeof(self) weakSelf = self

4.通知

#define HHNotiCenter [NSNotificationCenter defaultCenter]

5.UserDefault

#define HHUserDefaults [NSUserDefaults standardUserDefaults]

6.常用的宽高

#define HHScreenH [UIScreen mainScreen].bounds.size.height
#define HHScreenW [UIScreen mainScreen].bounds.size.width
#define HHScreenBounds [UIScreen mainScreen].bounds
#define HHKeyWindow [UIApplication sharedApplication].keyWindow
#define HHRootTabBarController (UITabBarController *)HHKeyWindow.rootViewController

7.OC 的框架

#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#pragma mark - 头文件
#import "xxxxxx"   //放入要用的头文件
#endif

8.沙盒路径

#define HHCaches [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject]

9.

内容持续更新中,有用就拿走........顺便点个赞,谢谢大家的支持!

相关文章

  • iOS 开发小经验

    iOS 开发中你是否遇到这些经验问题(一)iOS 开发中你是否遇到这些经验问题(二)iOS 日常工作之常用宏定义大全

  • iOS 常用宏定义

    iOS 开发中使用一些常用宏定义可以大大提高开发效率,提高代码的重用性.以下是一些常用的宏定义: 像这些宏定义,在...

  • iOS开发常用的工具类和宏定义

    iOS开发常用的工具类和宏定义 开发总结的工具类和宏 https://github.com/xiaoChen66...

  • iOS开发中常用的宏

    以下为iOS开发中常用宏: 引用:ios开发常用的宏,大家一起来收集 参考:ios开发常用的宏,大家一起来收集~

  • IOS开发中 常用的宏定义

    #ifndef iOS_Constants_h #define iOS_Constants_h /* ******...

  • ios拓展31-宏(define)和const的正确姿势

    在iOS开发中,经常用到宏定义,但是网上看一些博客的时候,有的说宏定义大量使用会重复拷贝,占用内存. 有的说不会...

  • iOS常用宏 定义

    iOS开发过程中,使用的一些常用宏定义 字符串是否为空#define kStringIsEmpty(str) ([...

  • iOS开发中常用的宏定义

    iOS开发中常用的宏定义 尺寸宏 打印宏 替换NSLog来使用,debug模式下可以打印很多方法名,行信息。 #...

  • iOS 开发常用宏定义

  • iOS开发常用宏定义

    做开发不久,经常会上网找一些资料,简书上的内容是看着比较顺眼的了;特此也想把平时工作中遇到的问题总结记录下来,希望...

网友评论

本文标题:iOS 开发中常用的宏定义

本文链接:https://www.haomeiwen.com/subject/hrszxxtx.html