UIView+YYAdd.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //
  2. // UIView+YYAdd.h
  3. // YYCategories <https://github.com/ibireme/YYCategories>
  4. //
  5. // Created by ibireme on 13/4/3.
  6. // Copyright (c) 2015 ibireme.
  7. //
  8. // This source code is licensed under the MIT-style license found in the
  9. // LICENSE file in the root directory of this source tree.
  10. //
  11. #import <UIKit/UIKit.h>
  12. /**
  13. Provides extensions for `UIView`.
  14. */
  15. @interface UIView (YYAdd)
  16. /**
  17. Shortcut to set the view.layer's shadow
  18. @param color Shadow Color
  19. @param offset Shadow offset
  20. @param radius Shadow radius
  21. */
  22. - (void)setLayerShadow:(UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius;
  23. /**
  24. Remove all subviews.
  25. @warning Never call this method inside your view's drawRect: method.
  26. */
  27. - (void)removeAllSubviews;
  28. /**
  29. Returns the view's view controller (may be nil).
  30. */
  31. @property (nonatomic, readonly) UIViewController *viewController;
  32. @property (nonatomic) CGFloat left; ///< Shortcut for frame.origin.x.
  33. @property (nonatomic) CGFloat top; ///< Shortcut for frame.origin.y
  34. @property (nonatomic) CGFloat right; ///< Shortcut for frame.origin.x + frame.size.width
  35. @property (nonatomic) CGFloat bottom; ///< Shortcut for frame.origin.y + frame.size.height
  36. @property (nonatomic) CGFloat width; ///< Shortcut for frame.size.width.
  37. @property (nonatomic) CGFloat height; ///< Shortcut for frame.size.height.
  38. @property (nonatomic) CGFloat centerX; ///< Shortcut for center.x
  39. @property (nonatomic) CGFloat centerY; ///< Shortcut for center.y
  40. @property (nonatomic) CGPoint origin; ///< Shortcut for frame.origin.
  41. @property (nonatomic) CGSize size; ///< Shortcut for frame.size.
  42. @end
  43. double YYDeviceSystemVersion();
  44. #ifndef kSystemVersion
  45. #define kSystemVersion YYDeviceSystemVersion()
  46. #endif
  47. #ifndef kiOS6Later
  48. #define kiOS6Later (kSystemVersion >= 6)
  49. #endif
  50. #ifndef kiOS7Later
  51. #define kiOS7Later (kSystemVersion >= 7)
  52. #endif
  53. #ifndef kiOS8Later
  54. #define kiOS8Later (kSystemVersion >= 8)
  55. #endif
  56. #ifndef kiOS9Later
  57. #define kiOS9Later (kSystemVersion >= 9)
  58. #endif
  59. CGSize YYDeviceScreenSize();
  60. /// 屏幕宽度
  61. #ifndef kScreenWidth
  62. #define kScreenWidth YYDeviceScreenSize().width
  63. #endif
  64. /// 屏幕高度
  65. #ifndef kScreenHeight
  66. #define kScreenHeight YYDeviceScreenSize().height
  67. #endif
  68. /// 屏幕大小
  69. #ifndef kScreenSize
  70. #define kScreenSize YYDeviceScreenSize()
  71. #endif
  72. /// 屏幕Scale
  73. #ifndef kScreenScale
  74. #define kScreenScale [UIScreen mainScreen].scale
  75. #endif
  76. /*
  77. Create UIColor with a hex string.
  78. Example: UIColorHex(0xF0F), UIColorHex(66ccff), UIColorHex(#66CCFF88)
  79. Valid format: #RGB #RGBA #RRGGBB #RRGGBBAA 0xRGB ...
  80. The `#` or "0x" sign is not required.
  81. */
  82. #ifndef UIColorHex
  83. #define UIColorHex(_hex_) [UIColor colorWithHexString:((__bridge NSString *)CFSTR(#_hex_))]
  84. #endif
  85. @interface UIColor (YYAdd)
  86. /**
  87. Creates and returns a color object from hex string.
  88. @discussion:
  89. Valid format: #RGB #RGBA #RRGGBB #RRGGBBAA 0xRGB ...
  90. The `#` or "0x" sign is not required.
  91. The alpha will be set to 1.0 if there is no alpha component.
  92. It will return nil when an error occurs in parsing.
  93. Example: @"0xF0F", @"66ccff", @"#66CCFF88"
  94. @param hexStr The hex string value for the new color.
  95. @return An UIColor object from string, or nil if an error occurs.
  96. */
  97. + (UIColor *)colorWithHexString:(NSString *)hexStr;
  98. /**
  99. Creates and returns a color object by add new color.
  100. @param add the color added
  101. @param blendMode add color blend mode
  102. */
  103. - (UIColor *)colorByAddColor:(UIColor *)add blendMode:(CGBlendMode)blendMode;
  104. @end