---恢复内容开始---

在IOS开发中,有一些方法常常需要用的,但是有很长的方法名,这造成了代码长,写起来累,我们可以通过宏定义了解决这些问题

比如说在代码布局的时候会遇上这样的问题,我们要获取上面一个的Y轴坐标,

有两种方法

通过坐标加上高度来计算

xx.frame.origin.y+xx.frame.size.height

还有一个略微简便的方法

CGRectGetMaxY(xx.frame)

都挺麻烦的,这时候就需要祭出宏定义来帮忙

#define MaxY(v)            CGRectGetMaxY((v).frame) //纵坐标加上控件的高度

通过这样的定义,下次我们获取Y坐标的时候只要轻轻的写上MaxY(xx)即可,是不是简单很多呢?

类似的还有加载图片的方法

#define IMAGENAMED(NAME)       [UIImage imageNamed:NAME]

这样就非常的方便,

下面是我整理的一个类

#ifndef Medical_Wisdom_UConstants_h
#define Medical_Wisdom_UConstants_h /******************************************************/ /**** debug log **/ //NSLog输出信息 #ifdef DEBUG #define DLog( s, ... ) NSLog( @"< %@:(%d) > %@", [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) #else #define DLog( s, ... ) #endif /*** DEBUG RELEASE */ #if DEBUG #define MCRelease(x) #else #define MCRelease(x) #endif /***** release *****/
#define NILRelease [x release], x = nil #pragma mark - Frame(宏 x,y,width,height) #define MainScreenScale [[UIScreen mainScreen]scale] //屏幕的分辨率 当结果为1时,显示的是普通屏幕,结果为2时,显示的是Retian屏幕
// App Frame Height&Width
#define Application_Frame [[UIScreen mainScreen] applicationFrame] //除去信号区的屏幕的frame
#define APP_Frame_Height [[UIScreen mainScreen] applicationFrame].size.height //应用程序的屏幕高度
#define App_Frame_Width [[UIScreen mainScreen] applicationFrame].size.width //应用程序的屏幕宽度
/*** MainScreen Height Width */ #define Main_Screen_Width [[UIScreen mainScreen] bounds].size.width //主屏幕的宽度
#define Main_Screen_Height [[UIScreen mainScreen] bounds].size.height //主屏幕的高度
#define Main_Screen_Height_without_top [[UIScreen mainScreen] bounds].size.height-64 //主屏幕的高度 // View 坐标(x,y)和宽高(width,height)
#define X(v) (v).frame.origin.x
#define Y(v) (v).frame.origin.y
#define WIDTH(v) (v).frame.size.width
#define HEIGHT(v) (v).frame.size.height #define MinX(v) CGRectGetMinX((v).frame) // 获得控件屏幕的x坐标
#define MinY(v) CGRectGetMinY((v).frame) // 获得控件屏幕的Y坐标 #define MidX(v) CGRectGetMidX((v).frame) //横坐标加上到控件中点坐标
#define MidY(v) CGRectGetMidY((v).frame) //纵坐标加上到控件中点坐标 #define MaxX(v) CGRectGetMaxX((v).frame) //横坐标加上控件的宽度
#define MaxY(v) CGRectGetMaxY((v).frame) //纵坐标加上控件的高度 #define CONTRLOS_FRAME(x,y,width,height) CGRectMake(x,y,width,height) // 系统控件的默认高度
#define kStatusBarHeight (20.f)
#define kTopBarHeight (44.f)
#define kBottomBarHeight (49.f) #define kCellDefaultHeight (44.f) #define KstatusBarAndNavigation (64.0)
// 当控件为全屏时的横纵左边
#define kFrameX (0.0)
#define kFrameY (0.0) #define kPhoneWithStatusNoPhone5Height (480.0)
#define kPhoneNoWithStatusNoPhone5Height (460.0)
#define kPhoneWithStatusPhone5Height (568.0)
#define kPhoneNoWithStatusPhone5Height (548.0) #define kPadFrameWidth (768.0)
#define kPadWithStatusHeight (1024.0)
#define kPadNoWithStatusHeight (1004.0) //中英状态下键盘的高度
#define kEnglishKeyboardHeight (216.f)
#define kChineseKeyboardHeight (252.f) #pragma mark - Funtion Method (宏 方法)
//PNG JPG 图片路径
#define PNGPATH(NAME) [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:NAME] ofType:@"png"]
#define JPGPATH(NAME) [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:NAME] ofType:@"jpg"]
#define PATH(NAME,EXT) [[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)] //加载图片
#define PNGIMAGE(NAME) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:@"png"]]
#define JPGIMAGE(NAME) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:@"jpg"]]
#define IMAGE(NAME,EXT) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:(NAME) ofType:(EXT)]]
#define IMAGENAMED(NAME) [UIImage imageNamed:NAME] //字体大小(常规/粗体)
#define BOLDSYSTEMFONT(FONTSIZE) [UIFont boldSystemFontOfSize:FONTSIZE]
#define SYSTEMFONT(FONTSIZE) [UIFont systemFontOfSize:FONTSIZE]
#define FONT(NAME,FONTSIZE) [UIFont fontWithName:(NAME) size:(FONTSIZE)] //颜色(RGB)
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)] #define BACKGROUND_COLOR [UIColor colorWithRed:22/255.0f green:29/255.0f blue:38/255.0f alpha:1]
//当前版本
#define FSystenVersion ([[[UIDevice currentDevice] systemVersion] floatValue])
#define DSystenVersion ([[[UIDevice currentDevice] systemVersion] doubleValue])
#define SSystemVersion ([[UIDevice currentDevice] systemVersion]) //当前语言
#define CURRENTLANGUAGE ([[NSLocale preferredLanguages] objectAtIndex:0]) //是否Retina屏
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) :NO)
//是否iPhone5
#define ISIPHONE [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone
#define ISIPHONE5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
#define ISIPHONE6 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
#define ISIPHONE6P ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO) //是否是iPad
#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #define YELLO_APP [UIColor colorWithRed:255/255 green:148.0/255 blue:28.0/255 alpha:1] // UIView - viewWithTag 通过tag值获得子视图
#define VIEWWITHTAG(_OBJECT,_TAG) [_OBJECT viewWithTag : _TAG] //应用程序的名字
#define AppDisplayName [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"] //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] //判断设备室真机还是模拟器
#if TARGET_OS_IPHONE
/** iPhone Device */
#endif #if TARGET_IPHONE_SIMULATOR
/** iPhone Simulator */
#endif #endif

这个在开发的时候可以略微的提高效率,OC的语法确实有点烦啊,赶快学swift吧,_

完整的代码可以在GitHub下载

---恢复内容结束---

IOS快速开发之常量定义的更多相关文章

  1. iOS项目开发实战——自己定义圆形进度提示控件

    iOS中默认的进度条是水平方向的进度条,这往往不能满足我们的需求. 可是我们能够自己定义类似的圆形的进度提示控件,主要使用iOS中的画图机制来实现. 这里我们要实现一个通过button点击然后圆形进度 ...

  2. 【PYQT5快速开发】重定义边框、QSS美化皮肤主题

    在用qt designer的基础上重定义边框 前言 作为一名技术工作者,偶有使用.开发工具的需求.制作工具时,既不想在界面上花太懂功夫,又想要工具模样与众不同,结果找半天找不到一键换装的功能/拍砖. ...

  3. ios 日常开发常用宏定义

      #pragma mark - 字体.颜色相关 #define kFONT_SIZE(f) [UIFont systemFontOfSize:(f)] #define kFONT_BOLD_SIZE ...

  4. 阿里巴巴Java开发手册(命名规范/常量定义篇)——查自己的漏-补自己的缺

    一.编程规约 (一) 命名规约 1. [强制]所有编程相关命名均不能以下划线或美元符号开始,也不能以下划线或美元符号结束. 反例: _name / __name / $Object / name_ / ...

  5. iOS 非ARC基本内存管理系列 -手把手教你ARC——iOS/Mac开发ARC入门和使用(转)

    手把手教你ARC——iOS/Mac开发ARC入门和使用 Revolution of Objective-c 本文部分实例取自iOS 5 Toturail一书中关于ARC的教程和公开内容,仅用于技术交流 ...

  6. 20个可以帮你简化iOS app开发流程的工具

    这里推荐20个可以帮你简化iOS app开发流程的工具.很多开发者都使用过这些工具,涉及原型和设计.编程.测试以及最后的营销,基本上涵盖了整个开发过程. 原型和设计 有了一个很好的创意后,你要做的不是 ...

  7. 点评阿里JAVA手册之编程规约(命名风格、常量定义、代码风格、控制语句、注释规约)

    下载原版阿里JAVA开发手册  [阿里巴巴Java开发手册v1.2.0] 本文主要是对照阿里开发手册,注释自己在工作中运用情况. 本文难度系数为一星(★) 码出高效.码出质量. 代码的字里行间流淌的是 ...

  8. 包建强的培训课程(7):iOS企业级开发实战

    @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...

  9. iOS视频流开发(1)—视频基本概念

    iOS视频流开发(1)-视频基本概念 手机比PC的优势除了便携外,她最重要特点就是可以快速方便的创作多媒体作品.照片分享,语音输入,视频录制,地理位置.一个成功的手机APP从产品形态上都有这其中的一项 ...

随机推荐

  1. [转载]值得推荐的C/C++框架和库

    值得学习的C语言开源项目 C++ 资源大全 值得学习的C语言开源项目 1.Webbench Webbench是一个在linux下使用的非常简单的网站压测工具.它使用fork()模拟多个客户端同时访问我 ...

  2. 跳跃表Skip List【附java实现】

    skip list的原理 Java中的LinkedList是一种常见的链表结构,这种结构支持O(1)的随机插入及随机删除, 但它的查找复杂度比较糟糕,为O(n). 假如我们有一个有序链表如下,如果我们 ...

  3. 完美逆向百度手机助手5.0底部菜单栏 - Android Tabhost 点击动画

    先看看百度手机助手5.0的样子: 发现他是用一个CustomTabHost.java来实现底部TabHost点击效果的,很漂亮,点击Tab的时候文字会上跑,图片会从底部跑出来的一个小动画. 下面我用自 ...

  4. 每一个web开发者都应该了解的HTTP/2

    我认为每一个 web 开发者都应该对这个支撑了整个 Web 世界的 HTTP 协议有所了解,这样才能帮助你更好的完成开发任务.在这篇文章中,我将讨论什么是 HTTP,它是怎么产生的,它的地位,以及我们 ...

  5. easyUI属性总结

    1.div easyui-window        生成一个window窗口样式.      属性如下:                   1)modal:是否生成模态窗口.true[是] fal ...

  6. android:Adb connection Error:远程主机强迫关闭了一个现有的连接

    用真机调试程序的时候,eclipse的console总是出现如下的错误“Adb connection Error:远程主机强迫关闭了一个现有的连接” 问题出现的原因:这是ddms调用adb引发的. 经 ...

  7. cocos2d-x项目过程记录(Objective-C转C++)

    (原创作品,欢迎转载,注明出处,谢谢:http://www.cnblogs.com/binxindoudou/admin/EditPosts.aspx?postid=3179335) 1.单例模式中, ...

  8. NSDateFormatter 格式说明

    格式化参数如下:    G: 公元时代,例如AD公元    yy: 年的后2位    yyyy: 完整年    MM: 月,显示为1-12    MMM: 月,显示为英文月份简写,如 Jan    M ...

  9. python之路,Day24 常用设计模式学习

    python之路,Day24 常用设计模式学习   本节内容 设计模式介绍 设计模式分类 设计模式6大原则 1.设计模式介绍 设计模式(Design Patterns) --可复用面向对象软件的基础 ...

  10. HighCharts常用设置(摘抄笔录)