/*
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. Oracle查看表结构的方法【我】

    Oracle查看表结构的方法   方法一: 在命令窗口下输入   DESC table_name;  回车       方法二: 在sql窗口下   SELECT DBMS_METADATA.GET_ ...

  2. 《最长的一帧》 osg3.4 osgViewer::View::init() osgViewer::Viewer::getContexts()

    开始:osgViewer/ViewerBase.cpp   389行,startThreading()函数,启动线程   void ViewerBase::startThreading() { if ...

  3. Windows7 安装docker工具的方法

    1.参考官方文档 https://docs.docker.com/toolbox/toolbox_install_windows/ 注意:因为我的电脑是windows10 家庭版,所以,无法使用 Do ...

  4. 性能测试-Linux资源监控⽅式

    Linux资源监控⽅式 1. 命令 2. 第三⽅⼯具(nmon) 3. LR(需要安装RPC相应服务包和开启服务)(略)   ⼀.命令 ⽅式 1. top (系统资源管理器) 2. vmstat (查 ...

  5. 定时杀死warn进程

    6 6 * * * /root/wz/mysqlRestart.sh    #MySQL restart7 6 * * * /bin/sh /home/warn/kill_.sh8 6 * * * / ...

  6. jQuery BlockUI Plugin Demo 6(Options)

    Options BlockUI's default options look (exactly) like this: // override these in your code to change ...

  7. (CVE-2017-7494)Samba远程代码执行[Linux]

    简介 此漏洞是针对开启了共享的smb服务 漏洞利用 启动msfconsole search is_known_pipename   搜索此模块 use exploit/linux/samba/is_k ...

  8. 【ARM-Linux开发】TI 关于Gstreamer使用的几个参考

    http://processors.wiki.ti.com/index.php/Example_GStreamer_Pipelines#H.264_RTP_Streaming http://proce ...

  9. python 列表推导式 - python基础入门(16)

    截止到目前为止,python基础内容已经学习了50%左右,在学习编程过程中,我们不仅要学习python语法,同时也需要学习如何把自己代码写的更美观,效率更高. 一.什么是推导式 推导式是从一个或者多个 ...

  10. 三个思路解决413 Request Entity Too Large报错处理

    最近一个项目当中,要求上传图片,并且限制图片大小,虽然在laravel当中已经添加了相关的表单验证来阻止文件过大的上传,然而当提交表单时,还没轮到laravel处理,nginx就先报错了.当你仔细看报 ...