UIView+Voice.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // UIView+Voice.m
  3. // UniversalApp
  4. //
  5. // Created by bogokj on 2019/12/16.
  6. // Copyright © 2019 voidcat. All rights reserved.
  7. //
  8. #import "UIView+Voice.h"
  9. @implementation UIView (Voice)
  10. /**
  11. * 设置部分圆角(绝对布局)
  12. *
  13. * @param corners 需要设置为圆角的角 UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight | UIRectCornerAllCorners
  14. * @param radii 需要设置的圆角大小 例如 CGSizeMake(20.0f, 20.0f)
  15. */
  16. - (void)addRoundedCorners:(UIRectCorner)corners
  17. withRadii:(CGSize)radii {
  18. UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:radii];
  19. CAShapeLayer* shape = [[CAShapeLayer alloc] init];
  20. [shape setPath:rounded.CGPath];
  21. self.layer.mask = shape;
  22. }
  23. /**
  24. * 设置部分圆角(相对布局)
  25. *
  26. * @param corners 需要设置为圆角的角 UIRectCornerTopLeft | UIRectCornerTopRight | UIRectCornerBottomLeft | UIRectCornerBottomRight | UIRectCornerAllCorners
  27. * @param radii 需要设置的圆角大小 例如 CGSizeMake(20.0f, 20.0f)
  28. * @param rect 需要设置的圆角view的rect
  29. */
  30. - (void)addRoundedCorners:(UIRectCorner)corners
  31. withRadii:(CGSize)radii
  32. viewRect:(CGRect)rect {
  33. UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corners cornerRadii:radii];
  34. CAShapeLayer* shape = [[CAShapeLayer alloc] init];
  35. [shape setPath:rounded.CGPath];
  36. self.layer.mask = shape;
  37. }
  38. - (void)addAppTopCornerRadius{
  39. UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(kTopCornerRadius, kTopCornerRadius)];
  40. CAShapeLayer* shape = [[CAShapeLayer alloc] init];
  41. [shape setPath:rounded.CGPath];
  42. self.layer.mask = shape;
  43. }
  44. - (void)addTopCornerRadius:(CGFloat)TopRadius{
  45. UIBezierPath* rounded = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(TopRadius, TopRadius)];
  46. CAShapeLayer* shape = [[CAShapeLayer alloc] init];
  47. [shape setPath:rounded.CGPath];
  48. self.layer.mask = shape;
  49. }
  50. @end