/*
1. 颜色
*/
#define PCBRGBColorA(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)/255.0]//RGBA
#define PCBRGBColor(r, g, b) PCBRGBColorA((r), (g), (b), 255)//RGB
#define PCBRandomColor PCBRGBColor(arc4random_uniform(255), arc4random_uniform(255), arc4random_uniform(255))//随机色
#define PCBColorFromRGB(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]// rgb颜色转换(16进制->10进制)
#define PCBWhiteColor [UIColor whiteColor]
#define PCBBlackColor [UIColor blackColor]
#define PCBDarkGrayColor [UIColor darkGrayColor]
#define PCBLightGrayColor [UIColor lightGrayColor]
#define PCBGrayColor [UIColor grayColor]
#define PCBRedColor [UIColor redColor]
#define PCBGreenColor [UIColor greenColor]
#define PCBBlueColor [UIColor blueColor]
#define PCBCyanColor [UIColor cyanColor]
#define PCBYellowColor [UIColor yellowColor]
#define PCBMagentaColor [UIColor magentaColor]
#define PCBOrangeColor [UIColor orangeColor]
#define PCBPurpleColor [UIColor purpleColor]
#define PCBBrownColor [UIColor brownColor]
#define PCBClearColor [UIColor clearColor] // PCB常见颜色
#define PCB_BlackColor PCBColorFromRGB(0x333333)
#define PCB_GrayColor PCBColorFromRGB(0x999999)
#define PCB_Gray_BgButtonColor PCBColorFromRGB(0xd1d1d1)
#define PCB_GreenColor PCBColorFromRGB(0x30c1ce)
#define PCB_BgColor PCBColorFromRGB(0xf1f1f1)
#define PCB_LineColor PCBColorFromRGB(0xe5e5e5) /*
2. 打印
*/
#ifdef DEBUG
#define PCBLog(...) NSLog(@"\n打印结果:\n %s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define PCBLog(...)
#endif #define PCBLogFunc NSLog(@"方法名:\n %s", __func__);//只打印函数名称
#define PCBLogResponseObject PCBLog(@"%@",responseObject);
#define PCBLogError PCBLog(@"%@",error);
#define PCBNSHomeDirectory PCBLog(@"%@",NSHomeDirectory()); /*
3. 单利
*/
//单例化一个类
#if __has_feature(objc_arc)//ARC #define SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(classname) \
\
+ (classname *)shared##classname; #define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \
\
static classname *shared##classname = nil; \
\
+ (classname *)shared##classname \
{ \
static dispatch_once_t pred; \
dispatch_once(&pred, ^{ shared##classname = [[classname alloc] init]; }); \
return shared##classname; \
} #else//MRC #define SYNTHESIZE_SINGLETON_FOR_CLASS_HEADER(classname) \
\
+ (classname *)shared##classname; #define SYNTHESIZE_SINGLETON_FOR_CLASS(classname) \
\
static classname *shared##classname = nil; \
\
+ (classname *)shared##classname \
{ \
static dispatch_once_t pred; \
dispatch_once(&pred, ^{ shared##classname = [[classname alloc] init]; }); \
return shared##classname; \
} \
\
- (id)copyWithZone:(NSZone *)zone \
{ \
return self; \
} \
\
- (id)retain \
{ \
return self; \
} \
\
- (NSUInteger)retainCount \
{ \
return NSUIntegerMax; \
} \
\
- (oneway void)release \
{ \
} \
\
- (id)autorelease \
{ \
return self; \
} #endif /*
4.字体
*/
/*
#define PCBFontName @"PingFangSC-Medium"
#define PCBSystemFontWithSize(R) [UIFont fontWithName: PCBFontName size: R] // 固定字体
#define PCBFont(float) PCBSystemFontWithSize(float)
// 可以适配的字体
#define PCBAdaptFont(float) PCBSystemFontWithSize(PCBAdapted_Width(float))
*/ // 字体大小适应
#define PCBFont(float) [UIFont systemFontOfSize:float]
#define PCBBoldFont(float) [UIFont boldSystemFontOfSize:float]
#define PCBFont_13 PCBFont(13)
#define PCBFont_14 PCBFont(14)
#define PCBFont_15 PCBFont(15)
#define PCBFont_17 PCBFont(17)
#define PCBFont_20 PCBFont(20) /*
5.尺寸 + 版本
*/
/*
iPhone X尺寸问题
分辨率1125*2436 (375*812)
导航栏为 44+44 原来为20+44
底部tabbar 49+34 其余屏幕 49+0
*/
#define IOS11 @available(iOS 11.0, *)
#define IPhoneX ([UIScreen mainScreen].bounds.size.width == 375.0f && [UIScreen mainScreen].bounds.size.height == 812.0f) // 尺寸
#define PCBScreen_Width ([UIScreen mainScreen].bounds.size.width)
#define PCBScreen_Height ([UIScreen mainScreen].bounds.size.height)
#define PCBStatusBar_Height [[UIApplication sharedApplication] statusBarFrame].size.height
#define PCBNavigationBar_Height self.navigationController.navigationBar.frame.size.height
#define PCBHeight_64 (PCBStatusBar_Height + PCBNavigationBar_Height)
#define PCBTabBar_Height (IPhoneX ? 83.f : 49.f)
#define PCBScreen_Bounds [UIScreen mainScreen].bounds
#define PCBShowView_Height (Screen_Height - PCBHeight_64 - PCBTabBar_Height) // 适配
// 现在产品设计稿有以iPhone6s为基准的
#define PCBScreenWidthRatio (PCBScreen_Width / 375.0)
#define PCBScreenHeightRatio (PCBScreen_Width / 375.0)//(PCBScreen_Height / 667.0)-适配ihopneX以屏幕宽度比例为准
#define PCBAdapted_Width(x) (ceilf((x) * PCBScreenWidthRatio))
#define PCBAdapted_Height(x) (ceilf((x) * PCBScreenHeightRatio))
#define PCBMarginWidth PCBAdapted_Width(8)
#define PCBHeight PCBAdapted_Height(8)
#define PCBLineViewHeight 0.5 /*
round:如果参数是小数,则求本身的四舍五入。
ceil:如果参数是小数,则求最小的整数但不小于本身.
floor:如果参数是小数,则求最大的整数但不大于本身.
*/ /*
6.缩写
*/
// 获取图片资源(本地)
#define PCBGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]
#define PCBString(object) [NSString stringWithFormat:@"%@",object] // 系统一些常用缩写
#define PCBNotificationCenter [NSNotificationCenter defaultCenter]
#define PCBApplication [UIApplication sharedApplication]
#define PCBKeyWindow [UIApplication sharedApplication].keyWindow
#define PCBAppDelegate [UIApplication sharedApplication].delegate #define UserDefaults [NSUserDefaults standardUserDefaults]
#define PCBSetUserDefaults(value,key) [UserDefaults setObject:value forKey:key];\
[UserDefaults synchronize]
#define PCBGetUserDefaults(key) [UserDefaults objectForKey:key]
#define PCBRemoveUserDefaults(key) [UserDefaults removeObjectForKey:key]
#define PCBNotificationCenter [NSNotificationCenter defaultCenter]
#define PCBNavigationView self.navigationController.view /*
7. 弱引用/强引用
*/
#define PCBWeakSelf(type) __weak typeof(type) weak##type = type;
#define PCBStrongSelf(type) __strong typeof(type) type = weak##type; /*
8. 圆角、边框
*/
#define PCBViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]] /*
9. 提示框
*/
//9.1AlertView
#define PCBAVShow(Message) [[[UIAlertView alloc]initWithTitle:@"提示" message:Message delegate:nil cancelButtonTitle:@"好的" otherButtonTitles:nil, nil] show] //9.2UIAlertController的宏定义
//参数中的 MESSAGE是提示内容, PCBVC是UIViewController就是你当前操作的页面,调用时直接传递 self
#define PCBACShow(Message,PCBVC) \
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:Message preferredStyle:UIAlertControllerStyleAlert]; \
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:nil]; \
[alertController addAction:okAction]; \
[PCBVC presentViewController:alertController animated:YES completion:nil]; /*
10. 判断字符串、数组、字典、对象为空
*/
//字符串是否为空
#define PCBStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
//数组是否为空
#define PCBArrayIsEmpty(array) ((array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0) ? YES : NO)
//字典是否为空
#define PCBDictIsEmpty(dic) ((dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0) ? YES : NO)
//是否是空对象
#define PCBObjectIsEmpty(_object) ((_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0)) ? YES : NO) /*
11. 获取一些路径
*/
//获取沙盒Document路径
#define PCBDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//获取沙盒temp路径
#define PCBTempPath NSTemporaryDirectory()
//获取沙盒Cache路径
#define PCBCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
//Library/Caches 文件路径
#define PCBFilePath ([[NSFileManager defaultManager] URLForDirectory:NSCachesDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:nil])
#endif /* AppMacros_h */

iOS-OC中常见的一些宏的更多相关文章

  1. iOS项目中常见的文件

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

  2. iOS开发中常见的一些异常

    iOS开发中常见的异常包括以下几种NSInvalidArgumentExceptionNSRangeExceptionNSGenericExceptionNSInternallnconsistency ...

  3. iOS面试中常见的算法题目

    一.前言 这里是在iOS求职中自己遇到的算法题,希望对大家有所帮助.不定期更新.如果大家想在线运行代码调试,可以将代码拷贝到这里.然后进行调试.下面就是常见的算法题目. 二.正文 1.就n的阶乘.(这 ...

  4. C++ 中常见预定义宏的使用

    http://blog.csdn.net/hgl868/article/details/7058906 替代字符串: #define DOWNLOAD_IMAGE_LOG /var/log/png.l ...

  5. iOS开发中常见bug!(内附解答方法)

    序言 你是否曾经修复了一个 bug ,随后又发现了一个跟刚修复 bug 有关的 bug ,又或是修复 bug 的方式引起了另一个 bug ? 然而这些问题是绝佳的学习机会.所以我们怎样尽可能多地从修复 ...

  6. iOS 开发中常见的设计模式

    最近有小伙伴问到在iOS开发中的几种设计模式,这里摘录一下别人的总结(因为已经感觉总结得差不多了,适用的可以阅读一下) 首先是开发中的23中设计模式分为三大类:1.创建型 2.结构型 3.行为型 (i ...

  7. iOS OC中桥接swift第三方库

    swift中有一些比较好的框架,比如绘图框架charts,最近项目中刚好用到,通过Pod的方式直接导入,xcode会自动生成charts-swift.h的文件,然后在需要导入的地方import < ...

  8. iOS中常见的一些宏

    原文链接 1.处理NSLog事件(开发者模式打印,发布者模式不打印) #ifdef DEBUG #define NSLog(FORMAT, ...) fprintf(stderr,"%s:% ...

  9. iOS中常见的自定义宏

    //字符串是否为空 #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str leng ...

  10. 转载iOS开发中常见的警告及错误

    iOS警告收录及科学快速的消除方法     前言:现在你维护的项目有多少警告?看着几百条警告觉得心里烦么?你真的觉得警告又不是错误可以完全不管么? 如果你也被这些问题困惑,可以和我一起进行下面的操作. ...

随机推荐

  1. 利用Python获取cookie的方法,相比java代码简便不少

    1.通过urllib库,是python的标准库,不需要另外引入,直接看代码,注意代码的缩进: # coding=UTF-8import cookielibimport urllib2 class Ry ...

  2. ABAP DEMO篇21 选择屏幕显示说明TEXT

    实现方式1: *&---------------------------------------------------------------------**& Report YCX ...

  3. MongoDB集群之分片技术应用 —— 学习笔记

    课程链接:https://www.imooc.com/learn/501 一.什么是分片? 分片:将数据进行2拆分,将数据水平的分散到不同的服务器上. 二.为什么要分片? 架构上:读写均衡.去中心化 ...

  4. 树莓派连接显示器后设置ssh服务开机自动开启

    进入命令行,然后执行: cd /boot sudo touch ssh sudo restart -r now 然后就重新启动了,重启好了会有依据提示. 然后可以输入ssh localhost进行一下 ...

  5. D-Link系列路由器漏洞挖掘

    参考 http://www.freebuf.com/articles/terminal/153176.html https://paper.seebug.org/429/ http://www.s3c ...

  6. Golang 异常/日志处理

    1.xerrors 异常 xerrors 包是一个非常棒的设计,不同于往常语言如java/php,因为go的errors只是一个string类型的映射,所以内存占用空间很少.这在golang的核心库和 ...

  7. 【ARM-Linux开发】Wi-Fi 应用工具wpa_supplicant

    wpa_supplicant是一个跨平台的无线安全管理软件,这里需要用它来对无线网络进行配置,wpa_supplicant相关工具已经移植好,包含在我们提供的文件系统中. 配置无线网络 wpa_sup ...

  8. Python练手项目:20行爬取全王者全英雄皮肤

    引言    王者荣耀大家都玩过吧,没玩过的也应该听说过,作为时下最火的手机MOBA游戏,咳咳,好像跑题了.我们今天的重点是爬取王者荣耀所有英雄的所有皮肤,而且仅仅使用20行Python代码即可完成. ...

  9. 20191011-构建我们公司自己的自动化接口测试框架-Config配置

    Config模块主要是为了存放的一些其他配置等的一个目录,当前目录存放日志配置文件 ################################################ [loggers] ...

  10. Image splicing forgery detection combining coarse to refined convolutional neural network and adaptive clustering

    粗到精的卷积神经网络与自适应聚类相结合的图像拼接篡改检测 研究方向:图像篡改检测 论文出处:ELSEVIER A类 学校:西安电子科技大学网络工程学院.重庆邮电大学计算机科学与技术学院 关键字:Spl ...