iOS 常用到的宏#define
//AppDelegate #define APPDELEGATE [(AppDelegate*)[UIApplication sharedApplication] delegate] //----------------------系统设备相关---------------------------- //获取设备屏幕尺寸 #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)//应用尺寸 #define APP_WIDTH [[UIScreen mainScreen]applicationFrame].size.width #define APP_HEIGHT [[UIScreen mainScreen]applicationFrame].size.height //获取系统版本 #define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue] #define CurrentSystemVersion [[UIDevice currentDevice] systemVersion] #define isIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]==4) #define isIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]==5) #define isIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]==6) #define isIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]==7) #define isIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]==8) #define isIOS9 ([[[UIDevice currentDevice] systemVersion] intValue]==9) #define isIOS10 ([[[UIDevice currentDevice] systemVersion] intValue]==10) #define isIOS11 ([[[UIDevice currentDevice] systemVersion] intValue]==11) #define isAfterIOS4 ([[[UIDevice currentDevice] systemVersion] intValue]>4) #define isAfterIOS5 ([[[UIDevice currentDevice] systemVersion] intValue]>5) #define isAfterIOS6 ([[[UIDevice currentDevice] systemVersion] intValue]>6) #define isAfterIOS7 ([[[UIDevice currentDevice] systemVersion] intValue]>7) #define isAfterIOS8 ([[[UIDevice currentDevice] systemVersion] intValue]>8) #define isAfterIOS9 ([[[UIDevice currentDevice] systemVersion] intValue]>9) #define isAfterIOS10 ([[[UIDevice currentDevice] systemVersion] intValue]>10) #define isAfterIOS11 ([[[UIDevice currentDevice] systemVersion] intValue]>11) //获取当前语言 #define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) //判断是否 Retina屏、设备是否%fhone 5、是否是iPad #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO) #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO) #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) //判断是真机还是模拟器 #if TARGET_OS_IPHONE //iPhone Device #endif #if TARGET_IPHONE_SIMULATOR //iPhone Simulator #endif //----------------------系统设备相关---------------------------- //----------------------内存相关---------------------------- //NSUserDefaults #define UserDefauleSet(value,key) [[NSUserDefaults standardUserDefaults]setObject:value forKey:key];
#define UserDefauleObject(key) [[NSUserDefaults standardUserDefaults]objectIsForcedForKey:key];
#define UserDefauleRemove(key)[[NSUserDefaults standardUserDefaults]removeObjectForKey:key]; //通知
#define NotificationAdd(action,name) [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(action:) name:name object:nil];
#define NotificationPost(name,dict) [[NSNotificationCenter defaultCenter]postNotificationName:name object:nil userInfo:dict];
#define NotificationRemove(name) [[NSNotificationCenter defaultCenter]removeObserver:self name:name object:nil];
//使用ARC和不使用ARC #if __has_feature(objc_arc) //compiling with ARC #else // compiling without ARC #endif //释放一个对象 #define SAFE_DELETE(P) if(P) { [P release], P = nil; } #define SAFE_RELEASE(x) [x release];x=nil //----------------------内存相关---------------------------- //----------------------图片相关---------------------------- //读取本地图片 #define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]] //定义UIImage对象 #define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]] //定义UIImage对象 #define ImageNamed(_pointer) [UIImage imageNamed:_pointer] //可拉伸的图片 #define ResizableImage(name,top,left,bottom,right) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right)] #define ResizableImageWithMode(name,top,left,bottom,right,mode) [[UIImage imageNamed:name] resizableImageWithCapInsets:UIEdgeInsetsMake(top,left,bottom,right) resizingMode:mode] //建议使用前两种宏定义,性能高于后者 //----------------------图片相关---------------------------- //----------------------颜色相关--------------------------- // rgb颜色转换(16进制->10进制) #define UIColorFromRGB(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颜色 #define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a] #define RGB(r,g,b) RGBA(r,g,b,1.0f) //背景色 #define BACKGROUND_COLOR [UIColor colorWithRed:242.0/255.0 green:236.0/255.0 blue:231.0/255.0 alpha:1.0] //清除背景色 #define CLEARCOLOR [UIColor clearColor] //----------------------颜色相关-------------------------- //----------------------其他---------------------------- //方正黑体简体字体定义 #define FONT(F) [UIFont fontWithName:@"FZHTJW--GB1-0" size:F] //file //读取文件的文本内容,默认编码为UTF-8 #define FileString(name,ext) [[NSString alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)] encoding:NSUTF8StringEncoding error:nil] #define FileDictionary(name,ext) [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]] #define FileArray(name,ext) [[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(name) ofType:(ext)]] //G-C-D #define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block) #define MAIN(block) dispatch_async(dispatch_get_main_queue(),block) //Alert #define ALERT(msg) [[[UIAlertView alloc] initWithTitle:nil message:msg delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil] show] //由角度获取弧度 有弧度获取角度 #define degreesToRadian(x) (M_PI * (x) / 180.0) #define radianToDegrees(radian) (radian*180.0)/(M_PI) //----------------------其他------------------------------- //----------------------视图相关---------------------------- //设置需要粘贴的文字或图片 #define PasteString(string) [[UIPasteboard generalPasteboard] setString:string]; #define PasteImage(image) [[UIPasteboard generalPasteboard] setImage:image]; //得到视图的left top的X,Y坐标点 #define VIEW_TX(view) (view.frame.origin.x) #define VIEW_TY(view) (view.frame.origin.y) //得到视图的right bottom的X,Y坐标点 #define VIEW_BX(view) (view.frame.origin.x + view.frame.size.width) #define VIEW_BY(view) (view.frame.origin.y + view.frame.size.height ) //得到视图的尺寸:宽度、高度 #define VIEW_W(view) (view.frame.size.width) #define VIEW_H(view) (view.frame.size.height) //得到frame的X,Y坐标点 #define FRAME_TX(frame) (frame.origin.x) #define FRAME_TY(frame) (frame.origin.y) //得到frame的宽度、高度 #define FRAME_W(frame) (frame.size.width) #define FRAME_H(frame) (frame.size.height) //----------------------视图相关---------------------------- //---------------------打印日志-------------------------- //Debug模式下打印日志,当前行,函数名 #if DEBUG #define DLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]); #else #define NSLog(FORMAT, ...) nil #endif //Debug模式下打印日志,当前行,函数名 并弹出一个警告 #ifdef DEBUG # define WDLog(fmt, ...) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; } #else # define NSLog(...) #endif //打印Frame #define LogFrame(frame) NSLog(@"frame[X=%.1f,Y=%.1f,W=%.1f,H=%.1f",frame.origin.x,frame.origin.y,frame.size.width,frame.size.height) //打印Point #define LogPoint(point) NSLog(@"Point[X=%.1f,Y=%.1f]",point.x,point.y) //---------------------打印日志--------------------------
iOS 常用到的宏#define的更多相关文章
- iOS常用数学常量宏
在实际工作中有些程序不可避免的需要使用数学函数进行计算,比如地图程序的地理坐标到地图坐标的变换.Objective-C做为ANSI C的扩展,使用C标准库头文件<math.h>中定义的数学 ...
- iOS学习——iOS 宏(define)与常量(const)的正确使用
概述 在iOS开发中,经常用到宏定义,或用const修饰一些数据类型,经常有开发者不知怎么正确使用,导致项目中乱用宏与const修饰.你能区分下面的吗?知道什么时候用吗? #define HSCode ...
- iOS - 常用宏定义和PCH文件知识点整理
(一)PCH文件操作步骤演示: 第一步:图文所示: 第二步:图文所示: (二)常用宏定义整理: (1)常用Log日志宏(输出日志详细可定位某个类.某个函数.某一行) //=============== ...
- 你遗忘的都在这里—iOS常用类型方法笔记
这些都是项目中常用但又常忘的方法,与大家分享一下. 一.NSString 创建字符串. NSString *astring = @"This is a String!"; 创建空 ...
- iOS开发经常使用宏定义
iOS开发经常使用宏定义 iOS开发中经常须要获取屏幕宽度高度,为view设置颜色,为imgagView设置图片等,我们都可定义一些宏,随时都可拿来使用,方便开发 <span style=&qu ...
- iOS 常用三方类库整理
iOS 常用三方类库整理 1:基于响应式编程思想的oc 地址:https://github.com/ReactiveCocoa/ReactiveCocoa 2:hud提示框 地址:https://gi ...
- iOS常用公共方法
iOS常用公共方法 字数2917 阅读3070 评论45 喜欢236 1. 获取磁盘总空间大小 //磁盘总空间 + (CGFloat)diskOfAllSizeMBytes{ CGFloat si ...
- iOS常用的忽略警告
在iOS开发过程中,偶尔会碰到一些编译器警告,如果能够确定该警告不会影响到程序的正常运行,则可以手动告诉编译器忽略掉这个警告 iOS常用的忽略警告类型: 1.方法弃用警告 #pragma clang ...
- IOS常用正则表达式
IOS常用正则表达式 正则表达式用于字符串处理.表单验证等场合,实用高效.现将一些常用的表达式收集于此,以备不时之需. 匹配中文字符的正则表达式: [\u4e00-\u9fa5] 评注:匹配中文还真是 ...
随机推荐
- 《Linux命令行与shell脚本编程大全》第十四章 处理用户输入
有时还会需要脚本能够与使用者交互.bash shell提供了一些不同的方法来从用户处获得数据, 包括命令行参数,命令行选项,以及直接从键盘读取输入的能力. 14.1 命令行参数 就是添加在命令后的数据 ...
- [贪心][高精]P1080 国王游戏(整合)
题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成一排,国王站在队伍的最 ...
- [最短路]信使(msner)
[题目描述] 战争时期,前线有n个哨所,每个哨所可能会与其他若干个哨所之间有通信联系.信使负责在哨所之间传递信息,当然,这是要花费一定时间的(以天为单位).指挥部设在第一个哨所.当指挥部下达一个命令后 ...
- 转:聚类、K-Means、例子、细节
今天说聚类,但是必须要先理解聚类和分类的区别,很多业务人员在日常分析时候不是很严谨,混为一谈,其实二者有本质的区别. 分类其实是从特定的数据中挖掘模式,作出判断的过程.比如Gmail邮箱里有垃圾邮件分 ...
- 算法帖——用舞蹈链算法(Dancing Links)求解俄罗斯方块覆盖问题
问题的提出:如下图,用13块俄罗斯方块覆盖8*8的正方形.如何用计算机求解? 解决这类问题的方法不一而足,然而核心思想都是穷举法,不同的方法仅仅是对穷举法进行了优化 用13块不同形状的俄罗斯方块(每个 ...
- JS的数据类型及转换(还是基础的东西)
朋友说我这是再自娱自乐,我只想说,你说的对
- Django contrib Comments 评论模块详解
老版本的Django中自带一个评论框架.但是从1.6版本后,该框架独立出去了,也就是本文的评论插件. 这个插件可给models附加评论,因此常被用于为博客文章.图片.书籍章节或其它任何东西添加评论. ...
- C#爬虫系列(一)——国家标准全文公开系统
网上有很多Python爬虫的帖子,不排除很多培训班借着AI的概念教Python,然后爬网页自然是其中的一个大章节,毕竟做算法分析没有大量的数据怎么成. C#相比Python可能笨重了些,但实现简单爬虫 ...
- C# Excel写入数据及图表
开发工具:VS2017 语言:C DotNet版本:.Net FrameWork 4.0及以上 使用的DLL工具名称:GemBox.Spreadsheet.dll (版本:37.3.30.1185) ...
- cookie和session有什么区别,请你谈谈cookie的缺点
1.区别: cookie机制采用的是在客户端保持状态的方案 session机制采用的是在服务端保持状态的方案 2.cookie: 优点: 1> 极高的扩展性和可用性 2> 通过编程方式,控 ...