UtilMacro.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // UtilMacro.h
  3. // RichTextEditDemo
  4. //
  5. // Created by aron on 2017/8/2.
  6. // Copyright © 2017年 aron. All rights reserved.
  7. //
  8. #ifndef MobileExperience_UtilMacro_h
  9. #define MobileExperience_UtilMacro_h
  10. #import <dlfcn.h>
  11. #import <sys/types.h>
  12. #define kScreenHeight [UIScreen mainScreen].bounds.size.height //获取屏幕高度
  13. #define kScreenWidth [UIScreen mainScreen].bounds.size.width //获取屏幕宽度
  14. #define _(x) NSLocalizedString(x, @"")
  15. #define CACHE_PATH [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0]
  16. /**
  17. * 定义单例
  18. *
  19. * @param
  20. * 使用方法:在.h文件中声明单例,使用AS_SINGLETON 在.m文件中定义单例,使用DEF_SINGLETON
  21. * 调用方法:使用[单例名称 sharedInstance]
  22. *
  23. */
  24. #undef AS_SINGLETON
  25. #define AS_SINGLETON \
  26. + (instancetype)sharedInstance;
  27. #undef DEF_SINGLETON
  28. #define DEF_SINGLETON \
  29. + (instancetype)sharedInstance{ \
  30. static dispatch_once_t once; \
  31. static id __singleton__; \
  32. dispatch_once( &once, ^{ __singleton__ = [[self alloc] init]; } ); \
  33. return __singleton__; \
  34. } \
  35. #define convertLength(x) x
  36. #define convertFontSize(x) x
  37. //通用颜色宏定义
  38. //参数格式为:FFFFFF
  39. #define colorWithRGB(rgbValue) colorWithRGBAndA(rgbValue, 1.0)
  40. //参数格式为:FFFFFF, 1.0
  41. #define colorWithRGBAndA(rgbValue, alphaValue) \
  42. [UIColor colorWithRed:((float)((0x##rgbValue & 0xFF0000) >> 16)) / 255.0 \
  43. green:((float)((0x##rgbValue & 0xFF00) >> 8)) / 255.0 \
  44. blue:((float)(0x##rgbValue & 0xFF)) / 255.0 alpha:alphaValue]
  45. //参数格式为:FFFFFFFF
  46. #define colorWithARGB(argbValue) \
  47. [UIColor colorWithRed:((float)((0x##argbValue & 0xFF0000) >> 16)) / 255.0 \
  48. green:((float)((0x##argbValue & 0xFF00) >> 8)) / 255.0 \
  49. blue:((float)(0x##argbValue & 0xFF)) / 255.0 \
  50. alpha:((float)((0x##argbValue & 0xFF000000) >> 24)) / 255.0]
  51. // 颜色宏定义
  52. #define SNColor(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1.0]
  53. #define SNColorARGB(a,r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:a]
  54. // 随机色宏定义
  55. #define SNRandomColor SNColorARGB(0.4, arc4random_uniform(256), arc4random_uniform(256), arc4random_uniform(256))
  56. // 工具类
  57. #define ValueOrEmpty(value) ((value)?(value):@"")
  58. #endif