SLShotFocusView.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // SLShotFocusView.m
  3. // DarkMode
  4. //
  5. // Created by wsl on 2019/9/23.
  6. // Copyright © 2019 wsl. All rights reserved.
  7. //
  8. #import "SLShotFocusView.h"
  9. @interface SLShotFocusView ()
  10. /** 遮罩 */
  11. //@property (nonatomic, strong) CAShapeLayer *maskLayer;
  12. /** 路径 */
  13. @property (nonatomic, strong) UIBezierPath *borderPath;
  14. @end
  15. @implementation SLShotFocusView
  16. - (instancetype)initWithFrame:(CGRect)frame {
  17. self = [super initWithFrame:frame];
  18. if (self) {
  19. // 初始化遮罩
  20. // self.maskLayer = [CAShapeLayer layer];
  21. // 设置遮罩
  22. // [self.layer setMask:self.maskLayer];
  23. // 初始化路径
  24. self.borderPath = [UIBezierPath bezierPath];
  25. self.userInteractionEnabled = YES;
  26. self.backgroundColor = [UIColor clearColor];
  27. }
  28. return self;
  29. }
  30. - (instancetype)init{
  31. if (self = [super init]) {
  32. // 初始化遮罩
  33. // self.maskLayer = [CAShapeLayer layer];
  34. // 设置遮罩
  35. // [self.layer setMask:self.maskLayer];
  36. // 初始化路径
  37. self.borderPath = [UIBezierPath bezierPath];
  38. self.userInteractionEnabled = YES;
  39. self.backgroundColor = [UIColor clearColor];
  40. }
  41. return self;
  42. }
  43. - (void)drawRect:(CGRect)rect {
  44. // 遮罩层frame
  45. // self.maskLayer.frame = self.bounds;
  46. self.borderPath = [UIBezierPath bezierPathWithRect:self.bounds];
  47. self.borderPath.lineCapStyle = kCGLineCapButt;//线条拐角
  48. self.borderPath.lineWidth = 2.0;
  49. UIColor *color = [UIColor colorWithRed:45/255.0 green:175/255.0 blue:45/255.0 alpha:1];
  50. [color set];// 设置边框线条颜色
  51. //起点
  52. [self.borderPath moveToPoint:CGPointMake(rect.size.width/2.0, 0)];
  53. //连线 上
  54. [self.borderPath addLineToPoint:CGPointMake(rect.size.width/2.0, 0+8)];
  55. [self.borderPath moveToPoint:CGPointMake(0, rect.size.width/2.0)];
  56. //连线 左
  57. [self.borderPath addLineToPoint:CGPointMake(0+8, rect.size.width/2.0)];
  58. [self.borderPath moveToPoint:CGPointMake(rect.size.width/2.0, rect.size.height)];
  59. //连线 下
  60. [self.borderPath addLineToPoint:CGPointMake(rect.size.width/2.0, rect.size.height - 8)];
  61. [self.borderPath moveToPoint:CGPointMake(rect.size.width, rect.size.height/2.0)];
  62. //连线 右
  63. [self.borderPath addLineToPoint:CGPointMake(rect.size.width - 8, rect.size.height/2.0)];
  64. [self.borderPath stroke];
  65. // 将这个path赋值给maskLayer的path
  66. // self.maskLayer.path = self.borderPath.CGPath;
  67. }
  68. @end