UIView+BYIBInspectable.m 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // UIView+BYIBInspectable.m
  3. // Prophet
  4. //
  5. // Created by Even on 17/3/27.
  6. // Copyright © 2017年 Even. All rights reserved.
  7. //
  8. #import "UIView+BYIBInspectable.h"
  9. @implementation UIView (BYIBInspectable)
  10. - (void)setCornerRadius:(NSInteger)cornerRadius{
  11. self.layer.cornerRadius = cornerRadius;
  12. self.layer.masksToBounds = cornerRadius > 0;
  13. }
  14. - (NSInteger)cornerRadius{
  15. return self.layer.cornerRadius;
  16. }
  17. - (void)setBorderWidth:(NSInteger)borderWidth{
  18. self.layer.borderWidth = borderWidth;
  19. }
  20. - (NSInteger)borderWidth{
  21. return self.layer.borderWidth;
  22. }
  23. - (void)setBorderColor:(UIColor *)borderColor{
  24. self.layer.borderColor = borderColor.CGColor;
  25. }
  26. - (UIColor *)borderColor{
  27. return [UIColor colorWithCGColor:self.layer.borderColor];
  28. }
  29. #pragma mark - hexRgbColor
  30. - (void)setHexRgbColor:(NSString *)hexRgbColor{
  31. NSScanner *scanner = [NSScanner scannerWithString:hexRgbColor];
  32. unsigned hexNum;
  33. if (![scanner scanHexInt:&hexNum]) return;
  34. self.backgroundColor = [self colorWithRGBHex:hexNum];
  35. }
  36. - (UIColor *)colorWithRGBHex:(UInt32)hex {
  37. int r = (hex >> 16) & 0xFF;
  38. int g = (hex >> 8) & 0xFF;
  39. int b = (hex) & 0xFF;
  40. return [UIColor colorWithRed:r / 255.0f
  41. green:g / 255.0f
  42. blue:b / 255.0f
  43. alpha:1.0f];
  44. }
  45. - (NSString *)hexRgbColor{
  46. return @"0xffffff";
  47. }
  48. - (void)setOnePx:(BOOL)onePx{
  49. if (onePx) {
  50. CGRect rect = self.frame;
  51. rect.size.height = 1.0 / [UIScreen mainScreen].scale;
  52. self.frame = rect;
  53. }
  54. }
  55. - (BOOL)onePx{
  56. return self.onePx;
  57. }
  58. @end