常用iOS宏定义

IMG_2384.JPG

1.获取屏幕高度和宽度

#define kScreenHeight [[UIScreen mainScreen] bounds].size.height
#define kScreenWidth [[UIScreen mainScreen] bounds].size.width

2.设置字体和字体大小

#define CHINESE_FONT_NAME  @"Heiti SC"
#define CHINESE_SYSTEM(x) [UIFont fontWithName:CHINESE_FONT_NAME size:x]
#define BOLDSYSTEMFONT(FONTSIZE) [UIFont boldSystemFontOfSize:FONTSIZE]
#define SYSTEMFONT(FONTSIZE)     [UIFont systemFontOfSize:FONTSIZE]
#define FONT(NAME, FONTSIZE)     [UIFont fontWithName:(NAME) size:(FONTSIZE)]

3.颜色HEX,RGB,RANDOM

#define HEXCOLOR(rgbvalue) [UIColor colorWithRed:(CGFloat)((rgbvalue&0xFF0000)>>16)/255.0 green:(CGFloat)((rgbvalue&0xFF00)>>8)/255.0 blue:(CGFloat)(rgbvalue&0xFF)/255.0 alpha:1]
#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 RANDOMCOLOR [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]

4.开发时打印,发布时不打印的NSLog

#ifdef DEBUG
#define LKLog(...) NSLog(@"%s 第%d行 \n %@\n\n",__func__,__LINE__,[NSString stringWithFormat:__VA_ARGS__])
#else
#define LKLog(...)
#endif

5.获取图片资源

#define IMG_NAME(name) [UIImage imageNamed:[NSString stringWithFormat:@"%@", name]]

6.判断机型

#define iPhone5 kScreenWidth == 320.0f && kScreenHeight == 568.0f
#define iPhone6_7 kScreenWidth == 375.0f && kScreenHeight == 667.0f
#define iPhone6P_7P kScreenWidth == 414.0f && kScreenHeight == 736.0f

7.沙盒目录

//获取沙盒 Document
#define kPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//获取temp
#define kPathTemp NSTemporaryDirectory()
//获取沙盒 Cache
#define kPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

8.App版本

#define AppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

9.系统版本

#define FSystemVersion    ([[[UIDevice currentDevice] systemVersion] floatValue])
#define DSystemVersion    ([[[UIDevice currentDevice] systemVersion] doubleValue])
#define SSystemVersion    ([[UIDevice currentDevice] systemVersion])
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • iOS开发过程中,使用的一些常用宏定义 字符串是否为空#define kStringIsEmpty(str) ([...
    goyohol阅读 5,425评论 30 85
  • APP本版号 系统版本号 判断是真机还是模拟器 屏幕尺寸 沙盒Cache路径 Debug模式打印 弱引用/强引用 ...
    那就这样吧_阅读 2,391评论 1 2
  • 一、iOS 中常用的宏 设置Dlog可以打印出类名,方法名,行数. #ifdef DEBUG #define DL...
    卟吃兎孒的罗卜阅读 304评论 2 2
  • 1、禁止手机睡眠[UIApplication sharedApplication].idleTimerDisabl...
    DingGa阅读 1,161评论 1 6
  • 第十六章 家长见面 那天晚上,Leslie送我回家。我既紧张又兴奋,其实从义卖的广场到我爸妈家里并没有很久,可是我...
    许多多多多阅读 317评论 1 0