iOS 常用宏定义
2016-02-26 18:17
531 查看
// App Frame
#define Application_Frame [[UIScreen mainScreen] applicationFrame]
// App Frame Height&Width
#define App_Frame_Height [[UIScreen mainScreen] applicationFrame].size.height
#define App_Frame_Width [[UIScreen mainScreen] applicationFrame].size.width
// MainScreen Height&Width
#define Main_Screen_Height [[UIScreen mainScreen] bounds].size.height
#define Main_Screen_Width [[UIScreen mainScreen] bounds].size.width
// 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)
#define MinY(v) CGRectGetMinY((v).frame)
#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 StatusBarHeight (20.f)
#define TopBarHeight (44.f)
#define BottomBarHeight (49.f)
#define CellDefaultHeight (44.f)
#define EnglishKeyboardHeight (216.f)
#define ChineseKeyboardHeight (252.f)
// 沙盒路径
#define PATH_OF_APP_HOME NSHomeDirectory()
#define PATH_OF_TEMP NSTemporaryDirectory()
#define PATH_OF_DOCUMENT [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
// 加载图片
#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)]]
// 颜色(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 RANDOM_UICOLOR [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1]
// View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]
// View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]
// 当前语言
#define CURRENTLANGUAGE ([[NSLocale preferredLanguages] objectAtIndex:0])
// 本地化字符串
/** NSLocalizedString宏做的其实就是在当前bundle中查找资源文件名“Localizable.strings”(参数:键+注释) */
#define LocalString(x, ...) NSLocalizedString(x, nil)
/** NSLocalizedStringFromTable宏做的其实就是在当前bundle中查找资源文件名“xxx.strings”(参数:键+文件名+注释) */
#define AppLocalString(x, ...) NSLocalizedStringFromTable(x, @"someName", nil)
// 时间间隔
#define kHUDDuration (1.f)
// 一天的秒数
#define SecondsOfDay (24.f * 60.f * 60.f)
// 秒数
#define Seconds(Days) (24.f * 60.f * 60.f * (Days))
// 一天的毫秒数
#define MillisecondsOfDay (24.f * 60.f * 60.f * 1000.f)
// 毫秒数
#define Milliseconds(Days) (24.f * 60.f * 60.f * 1000.f * (Days))
// app 信息
#define APP_STORE_URL @"itms-apps://itunes.apple.com/us/app/xiong-zhao/id1020593660?l=zh&ls=1&mt=8"
#define APP_STORE_INFO_URL @"https://itunes.apple.com/cn/lookup?id=1020593660"
#define VERSION [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleShortVersionString"]
// block self
#define BlockWeakObject(o) __typeof(o) __weak
#define BlockWeakSelf BlockWeakObject(self)
#define Application_Frame [[UIScreen mainScreen] applicationFrame]
// App Frame Height&Width
#define App_Frame_Height [[UIScreen mainScreen] applicationFrame].size.height
#define App_Frame_Width [[UIScreen mainScreen] applicationFrame].size.width
// MainScreen Height&Width
#define Main_Screen_Height [[UIScreen mainScreen] bounds].size.height
#define Main_Screen_Width [[UIScreen mainScreen] bounds].size.width
// 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)
#define MinY(v) CGRectGetMinY((v).frame)
#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 StatusBarHeight (20.f)
#define TopBarHeight (44.f)
#define BottomBarHeight (49.f)
#define CellDefaultHeight (44.f)
#define EnglishKeyboardHeight (216.f)
#define ChineseKeyboardHeight (252.f)
// 沙盒路径
#define PATH_OF_APP_HOME NSHomeDirectory()
#define PATH_OF_TEMP NSTemporaryDirectory()
#define PATH_OF_DOCUMENT [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]
// 加载图片
#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)]]
// 颜色(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 RANDOM_UICOLOR [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1]
// View 圆角和加边框
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]
// View 圆角
#define ViewRadius(View, Radius)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES]
// 当前语言
#define CURRENTLANGUAGE ([[NSLocale preferredLanguages] objectAtIndex:0])
// 本地化字符串
/** NSLocalizedString宏做的其实就是在当前bundle中查找资源文件名“Localizable.strings”(参数:键+注释) */
#define LocalString(x, ...) NSLocalizedString(x, nil)
/** NSLocalizedStringFromTable宏做的其实就是在当前bundle中查找资源文件名“xxx.strings”(参数:键+文件名+注释) */
#define AppLocalString(x, ...) NSLocalizedStringFromTable(x, @"someName", nil)
// 时间间隔
#define kHUDDuration (1.f)
// 一天的秒数
#define SecondsOfDay (24.f * 60.f * 60.f)
// 秒数
#define Seconds(Days) (24.f * 60.f * 60.f * (Days))
// 一天的毫秒数
#define MillisecondsOfDay (24.f * 60.f * 60.f * 1000.f)
// 毫秒数
#define Milliseconds(Days) (24.f * 60.f * 60.f * 1000.f * (Days))
// app 信息
#define APP_STORE_URL @"itms-apps://itunes.apple.com/us/app/xiong-zhao/id1020593660?l=zh&ls=1&mt=8"
#define APP_STORE_INFO_URL @"https://itunes.apple.com/cn/lookup?id=1020593660"
#define VERSION [[[NSBundle mainBundle] infoDictionary] valueForKey:@"CFBundleShortVersionString"]
// block self
#define BlockWeakObject(o) __typeof(o) __weak
#define BlockWeakSelf BlockWeakObject(self)
相关文章推荐
- 详解 iOS navigationBar 的设置问题 详解2 关于隐藏和透明问题
- ios 8.3 越狱失败错误代码 “-1001”的解决方案
- iOS开发调用系统通讯录获取电话号码
- iOS之沙盒(Sandbox)机制
- 起底多线程同步锁(iOS)
- ios runtime (2)
- ioS开发知识(三十一)
- iOS闭包循环引用精讲
- iOS:strong 与weak何时使用
- ios runtime(1)
- iOS中常用不可变字符串函数方法
- iOS 保持登陆状态
- iOS项目的完整重命名方法图文教程
- iOS小技巧
- 此证书的签发者无效 Your account already has a valid iOS Distribution certificate
- ios 性能优化一些比较好的资源
- iOS开发调试篇—Print Description of "string"
- sublime3 apicloud plugin配置iOS真机调试
- 如何让iOS从容地崩溃
- iOS cookie 的使用(相当重要)