iOS PCH文件使用

iOS中PCH文件的配置

  1. 新建.pch文件
  2. 在Bulid Setting中搜索prefix
  3. 预编译Precompile Prefix Header设置为Yes
  4. Prefix Header路径设置为:$(PRODUCT_NAME)/XXX.pch

PCH文件常用宏

  • 自定义NSLog
#ifdef DEBUG // 调试
#define NSLog(...)      NSLog(@"%s %d行 %@", __func__, __LINE__, [NSString stringWithFormat:__VA_ARGS__])
#else // 发布
#define NSLog(...)
#endif
  • 屏幕尺寸
//屏幕尺寸
#define ScreenW [UIScreen mainScreen].bounds.size.width
#define ScreenH [UIScreen mainScreen].bounds.size.height

#define ScaleWidth (LLScreenW / 375.f)
#define ScaleHeight (LLScreenH / 667)
  • 系统
//系统
#define iPhone6P ([UIScreen mainScreen].bounds.size.height == 736)
#define iPhone6 ([UIScreen mainScreen].bounds.size.height == 667)
#define iPhone5 ([UIScreen mainScreen].bounds.size.height == 568)
#define iPhone4 ([UIScreen mainScreen].bounds.size.height == 480)
#define iOS8 ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0)
  • 颜色
#define HUDBackgroundColor UIColorWithRGBA(41, 51, 63, 0.6)  //0.6

#define UIColorWithRGBA(r, g, b, a) [[UIColor alloc] initWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
#define UIColorWithRGB(r, g, b) UIColorWithRGBA(r, g, b, 1.0)
#define UIColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1]

#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]
#define UIColorFromRGBA(rgbValue,alphaValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:alphaValue]

#define tableViewBackgroundColor UIColorFromRGB(0xf7f7f7)  //tableview背景灰色

  • 其他
#define WeakSelf(weakSelf)  __weak __typeof(&*self)weakSelf = self;
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 相信很多iOS开发者都用过pch文件,在Xcode6之前,创建一个新工程Xcode会在Supporting fil...
    没有昵称的昵称没有阅读 7,946评论 2 17
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 172,982评论 25 708
  • NSAssertNSAssert()是一个宏,用于开发阶段调试程序中的Bug,通过为NSAssert()传递条件表...
    f2efa87f6528阅读 355评论 0 0
  • 我这一生才过完三分之一,但我不知道后面的三分之二会不会到来,不知道是自己的性格使然还是本该如此,二十出头的年龄应当...
    回看来时的路阅读 274评论 1 1