iOS-OC中常见的一些宏
/*
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中常见的一些宏的更多相关文章
- iOS项目中常见的文件
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
- iOS开发中常见的一些异常
iOS开发中常见的异常包括以下几种NSInvalidArgumentExceptionNSRangeExceptionNSGenericExceptionNSInternallnconsistency ...
- iOS面试中常见的算法题目
一.前言 这里是在iOS求职中自己遇到的算法题,希望对大家有所帮助.不定期更新.如果大家想在线运行代码调试,可以将代码拷贝到这里.然后进行调试.下面就是常见的算法题目. 二.正文 1.就n的阶乘.(这 ...
- C++ 中常见预定义宏的使用
http://blog.csdn.net/hgl868/article/details/7058906 替代字符串: #define DOWNLOAD_IMAGE_LOG /var/log/png.l ...
- iOS开发中常见bug!(内附解答方法)
序言 你是否曾经修复了一个 bug ,随后又发现了一个跟刚修复 bug 有关的 bug ,又或是修复 bug 的方式引起了另一个 bug ? 然而这些问题是绝佳的学习机会.所以我们怎样尽可能多地从修复 ...
- iOS 开发中常见的设计模式
最近有小伙伴问到在iOS开发中的几种设计模式,这里摘录一下别人的总结(因为已经感觉总结得差不多了,适用的可以阅读一下) 首先是开发中的23中设计模式分为三大类:1.创建型 2.结构型 3.行为型 (i ...
- iOS OC中桥接swift第三方库
swift中有一些比较好的框架,比如绘图框架charts,最近项目中刚好用到,通过Pod的方式直接导入,xcode会自动生成charts-swift.h的文件,然后在需要导入的地方import < ...
- iOS中常见的一些宏
原文链接 1.处理NSLog事件(开发者模式打印,发布者模式不打印) #ifdef DEBUG #define NSLog(FORMAT, ...) fprintf(stderr,"%s:% ...
- iOS中常见的自定义宏
//字符串是否为空 #define kStringIsEmpty(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str leng ...
- 转载iOS开发中常见的警告及错误
iOS警告收录及科学快速的消除方法 前言:现在你维护的项目有多少警告?看着几百条警告觉得心里烦么?你真的觉得警告又不是错误可以完全不管么? 如果你也被这些问题困惑,可以和我一起进行下面的操作. ...
随机推荐
- java-selenium 框架例子
package mavenweb2; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.o ...
- 二进制包安装Mysql
(1).准备工作 前往mysql官网下载二进制安装包,https://dev.mysql.com/downloads/mysql/5.7.html#downloads(注意:选择操作系统时选Linux ...
- iOS-AVFoundation生成缩略图
使用MPMoviePlayerController来生成缩略图足够简单,但是如果仅仅是是为了生成缩略图而不进行视频播放的话,此刻使用 MPMoviePlayerController就有点大材小用了.其 ...
- MATLAB知识-解决因缺少libsvm 而运行出现Y must be a vector or a character array.
matlab版本R2014b 最近运行一个使用svmtrain的程序,出现以下错误: 这是因为是在设定路径里面没有libsvm.辛亏有一位师姐的电脑里面有libsvm的包,我直接用了,这样就不需要下载 ...
- mybatis 一对多,多对一配置
一. 简介: 本实例使用顾客和订单的例子做说明: 一个顾客可以有多个订单, 一个订单只对应一个顾客 二. 例子: 1. 代码结构图: 2. 建表语句: CREATE DATABASE test; US ...
- CentOS使用yum安装jdk
1.查看系统版本命令 cat /etc/issue 2.查看yum包含的jdk版本 yum search java 或者 yum list java* 版本 jre jdk 1.8 java-1.8. ...
- poj2074(求直线的交点)
题目链接:https://vjudge.net/problem/POJ-2074 题意:给定L1(Housing Line),L2(properity line),和一些L[i](obstructio ...
- ASP.NET请求过程-基本过程
客户端发送请求到达服务器 输入域名->DNS解析->指定IP 服务器(如果网页直接输入IP地址则直接到服务器)->请求到达服务器->HTTP.SYS接受HTTP请求->转 ...
- Python 实现把两个排好序的的列表合并成一个排序列表
列表是升序的 # -*- coding: utf-8 -*- # 合并两个排序的数组 def merge_list(a, b): if not a: return b if not b: return ...
- 微软的一道网红Java面试题
题目: 给定一个int类型数组:int[] array = new int[]{12, 2, 3, 3, 34, 56, 77, 432}, 让该数组的每个位置上的值去除以首位置的元素,得到的结果,作 ...