宏定义在很多方面都会使用,例如定义高度、判断iOS系统、工具类,还有诸如文件路径、服务端api接口文档。为了对宏能够快速定位和了解其功能,我们最好在定义的时候将其放入特定的头文件中

    定义尺寸类的宏

DimensMacros.h
//状态栏高度
#define STATUS_BAR_HEIGHT 20
//NavBar高度
#define NAVIGATION_BAR_HEIGHT 44
//状态栏 + 导航栏 高度
#define STATUS_AND_NAVIGATION_HEIGHT ((STATUS_BAR_HEIGHT) + (NAVIGATION_BAR_HEIGHT)) //屏幕 rect
#define SCREEN_RECT ([UIScreen mainScreen].bounds) #define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width) #define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height) #define CONTENT_HEIGHT (SCREEN_HEIGHT - NAVIGATION_BAR_HEIGHT - STATUS_BAR_HEIGHT) //屏幕分辨率
#define SCREEN_RESOLUTION (SCREEN_WIDTH * SCREEN_HEIGHT * ([UIScreen mainScreen].scale)) //广告栏高度
#define BANNER_HEIGHT 215 #define STYLEPAGE_HEIGHT 21 #define SMALLTV_HEIGHT 77 #define SMALLTV_WIDTH 110 #define FOLLOW_HEIGHT 220 #define SUBCHANNEL_HEIGHT 62 .定义沙盒目录文件的宏 PathMacros.h
//文件目录
#define kPathTemp NSTemporaryDirectory()
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]
#define kPathSearch [kPathDocument stringByAppendingPathComponent:@"Search.plist"] #define kPathMagazine [kPathDocument stringByAppendingPathComponent:@"Magazine"]
#define kPathDownloadedMgzs [kPathMagazine stringByAppendingPathComponent:@"DownloadedMgz.plist"]
#define kPathDownloadURLs [kPathMagazine stringByAppendingPathComponent:@"DownloadURLs.plist"]
#define kPathOperation [kPathMagazine stringByAppendingPathComponent:@"Operation.plist"] #define kPathSplashScreen [kPathCache stringByAppendingPathComponent:@"splashScreen"]
#endif .工具类的宏 UtilsMacros.h
//Log utils marco #define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__); #ifdef DEBUG
#define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
#define DLog(...)
#endif #ifdef DEBUG
#define ULog(...)
//#define ULog(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 ULog(...)
#endif //System version utils #define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending) // 获取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 IsPortrait ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown) #define IsNilOrNull(_ref) (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]])) //角度转弧度
#define DEGREES_TO_RADIANS(d) (d * M_PI / 180) //大于等于7.0的ios版本
#define iOS7_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0") //大于等于8.0的ios版本
#define iOS8_OR_LATER SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0") //iOS6时,导航VC中view的起始高度
#define YH_HEIGHT (iOS7_OR_LATER ? 64:0) //获取系统时间戳
#define getCurentTime [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]] .通知Notification相关的宏 NotificationMacros.h
//系统Notification定义 #define TNCancelFavoriteProductNotification @"TNCancelFavoriteProductNotification" //取消收藏时
#define TNMarkFavoriteProductNotification @"TNMarkFavoriteProductNotification" //标记收藏时 #define kNotficationDownloadProgressChanged @"kNotficationDownloadProgressChanged" //下载进度变化
#define kNotificationPauseDownload @"kNotificationPauseDownload" //暂停下载
#define kNotificationStartDownload @"kNotificationStartDownload" //开始下载 #define kNotificationDownloadSuccess @"kNotificationDownloadSuccess" //下载成功
#define kNotificationDownloadFailed @"kNotificationDownloadFailed" //下载失败
#define kNotificationDownloadNewMagazine @"kNotificationDownloadNewMagazine" 服务端API接口的宏 APIStringMacros.h
//////////////////////////////////////////////////////////////////////////////////////////////////
//接口名称相关 #ifdef DEBUG
//Debug状态下的测试API
#define API_BASE_URL_STRING @"http://boys.test.companydomain.com/api/" #else
//Release状态下的线上API
#define API_BASE_URL_STRING @"http://www.companydomain.com/api/" #endif //接口
#define GET_CONTENT_DETAIL @"channel/getContentDetail" //获取内容详情(含上一个和下一个) #define GET_COMMENT_LIST @"comment/getCommentList" //获取评论列表 #define COMMENT_LOGIN @"comment/login" //获取评论列表 #define COMMENT_PUBLISH @"comment/publish" //发布评论 #define COMMENT_DELETE @"comment/delComment" //删除评论 #define LOGINOUT @"common/logout" //登出 还有很多其他类型的宏,此处不一一列举

iOS宏定义的使用与规范的更多相关文章

  1. 转 iOS宏定义的使用与规范

    宏定义在很多方面都会使用,例如定义高度.判断iOS系统.工具类,还有诸如文件路径.服务端api接口文档.为了对宏能够快速定位和了解其功能,我们最好在定义的时候将其放入特定的头文件中,下面我抛砖引玉,对 ...

  2. ios宏定义字符串

    ios宏定义字符串 #define objcString(str) @""#str"" 使用效果: objcString(字符串)

  3. ios 宏定义 系统版本 判定

    当需要判断iOS系统版本的时候,相信很多人都会这么干: #define SystemVersion [[UIDevice currentDevice] systemVersion].floatValu ...

  4. iOS宏定义

    1.__OBJC__宏定义作用 在.pch 文件中一般都会自动加上这句宏定义,表示宏内引用的文件确保只被使用Objective-C语言的文件所引用,保证引用关系的清晰.因为在一个OC工程中,可能包含. ...

  5. 高效的iOS宏定义

    iOS开发过程中使用一些常用的宏可以提高开发效率,提高代码的重用性:将这些宏放到一个头文件里然后再放到工程中的-Prefix.pch文件中(或者直接放到-Prefix.pch中)直接可以使用,灰常方便 ...

  6. ios宏定义学习

    宏简介: 宏是一种批量处理的称谓.一般说来,宏是一种规则或模式,或称语法替换 ,用于说明某一特定输入(通常是字符串)如何根据预定义的规则转换成对应的输出(通常也是字符串).这种替换在预编译时进行,称作 ...

  7. ios宏定义应该呆在恰当的地方

    项目为了看起来整洁 并减少不必要的多次拼写 我们会把这样的方法 做成宏定义 那么问题来了 很多文件同时用到一个或多个宏定义 写完之后就会变成这个样子 看起来很乱 阅读性也不好 那么问题来了怎么解决嘞 ...

  8. IOS 宏定义一个单例

    有时候是不是因为频繁地创建一个单例对象而头疼,一种方式要写好多遍?当然你可以用OC语言进行封装.但下面将介绍一种由C语言进行的封装.只要实现下面的方法,以后建单例对象只要二句话. 1.新建一个.h文件 ...

  9. iOS 宏定义_16进制色值转化为RGB返回UIColor类型对象

    // 十六进制颜色 #define COLOR_WITH_HEX(hexValue) [UIColor colorWithRed:((float)((hexValue & 0xFF0000) ...

随机推荐

  1. xtrabackup_binlog_pos_innodb 和 xtrabackup_binlog_info

    用过 xtrabackup 工具的 innobackupex 脚本备份数据的人可能会注意到,–apply-log 处理过的备份数据里有两个文件说明该备份数据对应的 binlog 的文件名和位置.但有时 ...

  2. [Xamarin] 動態載入Fragment (转帖)

    這篇我們來動態加入,一樣務求好懂簡單 1.一樣先將專案調整成3.0以上版本 2.首先建立自定Control的Layout \Resources\Layout\MyControlLayout1.axml ...

  3. angular.js 例子

    angular.js是一个前端的MVC框架,12年的时候曾近在一个portal平台的项目中使用过. 下面给出一个angular.js的典型例子,涵盖一些基础的知识点,用以复习备忘: <html ...

  4. nginx(1、正向代理)

    正向代理是指客户端通过代理服务器访问某一个服务器,最常见的例子是内网用户通过代理访问外网,以及所谓的“FQ”. 在windows下实例如下: 1.下载安装包:nginx-1.7.9.zip: 2.解压 ...

  5. 单一职责原则(Single Responsibility Principle)

    单一职责原则(SRP:The Single Responsibility Principle) 一个类应该有且只有一个变化的原因. There should never be more than on ...

  6. html表格相关

    <html> <head> <style type="text/css"> thead {color:green} tbody {color:b ...

  7. [ACM_动态规划] 嵌套矩形

    问题描述:有n个矩阵,每个矩阵可以用两个整数a,b来表示 ,表示他的长和宽,矩阵X (a,b) 可以 嵌套 到Y (c,d) 里面当且仅当 a < c &&  b < d  ...

  8. 在js中对时间类型格式化字符串

    Date.prototype.toString = function (format) { if (format == null) { format = "yyyy-MM-dd HH:mm: ...

  9. mac下搭建lua环境

    mac下安装lua(可借助:rudix 地址:http://rudix.org) curl -s https://raw.githubusercontent.com/rudix-mac/rpm/201 ...

  10. 每天一个linux命令(43):killall命令

    Linux系统中的killall命令用于杀死指定名字的进程(kill processes by name).我们可以使用kill命令杀死指定进程PID的进程,如果要找到我们需要杀死的进程,我们还需要在 ...