博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ios项目常用的宏
阅读量:6231 次
发布时间:2019-06-21

本文共 7523 字,大约阅读时间需要 25 分钟。

hot3.png

#define SeverAddress                        @""//api服务#define kAPI                                [ApiService shareApiService]//屏幕适配因子#define kPERCENT(f)                         (f * [UIScreen mainScreen].bounds.size.width / 375.00)//普通字体#define FONT(f)                             [UIFont systemFontOfSize:(f)]//屏幕适应字体#define FONT_RATIO(f)                       [UIFont systemFontOfSize:(f * [UIScreen mainScreen].bounds.size.width / 375.00)]//屏幕宽度,高度,bounds,size#define WIDTH                               [UIScreen mainScreen].bounds.size.width#define HEIGHT                              [UIScreen mainScreen].bounds.size.height#define kSCREEN_BOUNDS                      [[UIScreen mainScreen] bounds]#define kSCREEN_BOUNDS_SIZE                 [[[UIScreen mainScreen] bounds] size]//view的frame因子#define View_FRAME_W(v)                     v.frame.size.width#define View_FRAME_H(v)                     v.frame.size.height#define View_FRAME_X(v)                     v.frame.origin.x#define View_FRAME_Y(v)                     v.frame.origin.y//RGB#define RGBA(r, g, b, a)                    [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]#define HexRGB(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]//随机色#define kRandomColor                        [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]//通用灰色线#define kLine_GrayColor                     [UIColor colorWithRed:231/255.f green:231/255.f blue:231/255.f alpha:0.8]//通用背景颜色#define kBackground_GrayColor               [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0]//定义UIImage对象#define GetImgWithName(imgName)             [UIImage imageNamed:[NSString stringWithFormat:@"%@",imgName]]//一些缩写#define kApplication                        [UIApplication sharedApplication]#define kUserDefaults                       [NSUserDefaults standardUserDefaults]#define kNotificationCenter                 [NSNotificationCenter defaultCenter]//App版本,ios系统版本#define APP_VERSION                         [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]#define IOS_SYSTEM_VERSION                  [[[UIDevice currentDevice] systemVersion] doubleValue]//沙盒目录文件下获取temp,Document,Cache#define kPathTemp                           NSTemporaryDirectory()#define kPathDocument                       [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]#define kPathCache                          [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]//写入defaults#define UserDefaults_WriteObj(object, key)  [[NSUserDefaults standardUserDefaults] setObject:(object) forKey:(key)]//读取defaults#define UserDefaults_ReadObj(key)           [[NSUserDefaults standardUserDefaults] objectForKey:(key)]//从defaults移除#define UserDefaults_RemoveObjForKey(key)   [[NSUserDefaults standardUserDefaults] removeObjectForKey:(key)]//defaults写入磁盘#define UserDefaults_Synchronize            [[NSUserDefaults standardUserDefaults] synchronize]//获取当前语言#define kCurrentLanguage                    ([[NSLocale preferredLanguages] objectAtIndex:0])//判断是否为iPhone#define kisIPhone                           (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)//判断是否为iPad#define kisIPad                             (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)//弱引用,强引用#define kWeakSelf(type)                     __weak typeof(type) weak##type = type#define kStrongSelf(type)                   __strong typeof(type) type = weak##type//由角度转换弧度#define kDegreesToRadian(x)                 (M_PI * (x) / 180.0)//由弧度转换角度#define kRadianToDegrees(radian)            (radian * 180.0) / (M_PI)//获取一段时间间隔#define kStartTime                          CFAbsoluteTime start = CFAbsoluteTimeGetCurrent()#define kEndTime_Log                        NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)//设置圆角,边框,边框颜色#define SetViewBorder(View, Radius, BorderWidth, BorderColor)\\[View.layer setCornerRadius:(Radius)];\[View.layer setMasksToBounds:YES];\[View.layer setBorderWidth:(Width)];\[View.layer setBorderColor:[Color CGColor]]//获取屏幕宽度与高度(考虑横屏)#define kScreenWidth \([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width)#define kScreenHeight \([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height)#define kScreenSize \([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size)//字典取值//字典祛空(如果空返回@"")#define Dictionary(dic,key)                   (dic[key] ? dic[key] : @"")//获取字典的key对应的String#define DictionaryStringWithKey(dic,key)      [NSString stringWithFormat:@"%@",Dictionary(dic,key)]//获取字典的key对应的int#define DictionaryIntWithKey(dic,key)         [DictionaryStringWithKey(dic,key) intValue]//获取字典的key对应的intger#define DictionaryIntegerWithKey(dic,key)     [DictionaryStringWithKey(dic,key) integerValue]//获取字典的key对应的float#define DictionaryFloatWithKey(dic,key)       [DictionaryStringWithKey(dic,key) floatValue]//获取字典的key对应的bool#define DictionaryBoolWithKey(dic,key)        [DictionaryStringWithKey(dic,key) boolValue]//数字类型转化字符串#define IntegerToString(num)                  [NSString stringWithFormat:@"%ld",num]#define FloatIntToString(num)                 [NSString stringWithFormat:@"%.0f",num]#define FloatToString(num)                    [NSString stringWithFormat:@"%.2f",num]#define IntToString(num)                      [NSString stringWithFormat:@"%d",num]//字符串是否为空#define kStringIsEmpty(str)       ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )//数组是否为空#define kArrayIsEmpty(array)      (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)//字典是否为空#define kDictIsEmpty(dic)         (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)//是否是空对象#define kObjectIsEmpty(_object)   (_object == nil \|| [_object isKindOfClass:[NSNull class]] \|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))//判断是真机还是模拟器#if TARGET_OS_IPHONE//真机#endif#if TARGET_IPHONE_SIMULATOR//模拟器#endif// 自定义Log日志(1)#if DEBUG#define NSLog(FORMAT, ...)  fprintf(stderr, "[%s: %d行] %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);#else#define NSLog(FORMAT, ...)  nil#endif// debug和release模式NSLog(2)//#ifdef DEBUG//#define NSLog(...)               NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])//#else//#define NSLog(...)//#endif#define CLog(format, ...)  NSLog1(format, ## __VA_ARGS__)#define NSLog1(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);//打印完整json

 

还有别人写的,转载下,可以看看

https://www.jianshu.com/p/0d380a1eff33

转载于:https://my.oschina.net/LBBB/blog/1841335

你可能感兴趣的文章
实例:某大型企业遭受勒索蠕虫袭击纪实
查看>>
OA选型之技术与性价比
查看>>
《Clojure数据分析秘笈》——1.8节从网页表中抓取数据
查看>>
《交互式程序设计 第2版》一3.6 导入外部库
查看>>
“云计算”让城市智慧起来
查看>>
Google计划收购数据科学社区Kaggle
查看>>
中国RFID市场规模及结构浅析
查看>>
厂商掘金智能家居市场 三大路径殊途同归
查看>>
京津冀大数据走廊:张北风电光伏成亮点
查看>>
任正非:80后90后是一代将星在闪烁
查看>>
Oracle 12c多租户特性详解:PDB 的备份与恢复
查看>>
《Adobe Illustrator CS4中文版经典教程》—第0课0.1节简 介
查看>>
Dat Data 13.5.1 发布,点对点数据共享
查看>>
在浏览器中体验 Ubuntu
查看>>
中国证实互联网故障源于根服务器遭攻击
查看>>
《OpenGL ES应用开发实践指南:Android卷》—— 1.3 初始化OpenGL
查看>>
微软正式封杀 7 代酷睿、Ryzen 运行 Win7!补丁断更
查看>>
Chrome 50 终止支持 Windows XP 和 OS X 10.6
查看>>
Java集合细节(三):subList的缺陷
查看>>
告别 Unity,Ubuntu 最新构建版启用 GNOME
查看>>