BogoDrawView.m 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. //
  2. // BogoDrawView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2021/7/31.
  6. // Copyright © 2021 xfg. All rights reserved.
  7. //
  8. #import "BogoDrawView.h"
  9. @implementation BogoDrawView
  10. {
  11. CGPoint _startPoint;
  12. CGPoint _middlePoint;
  13. CGPoint _endPoint;
  14. UIColor *_color;
  15. }
  16. - (instancetype)initStartPoint:(CGPoint)startPoint
  17. middlePoint:(CGPoint)middlePoint
  18. endPoint:(CGPoint)endPoint
  19. color:(UIColor*)color
  20. {
  21. self = [super init];
  22. if (self)
  23. {
  24. _startPoint = startPoint;
  25. _middlePoint = middlePoint;
  26. _endPoint = endPoint;
  27. _color = color;
  28. self.backgroundColor = [UIColor clearColor];
  29. }
  30. return self;
  31. }
  32. - (void)drawRect:(CGRect)rect
  33. {
  34. CGContextRef context = UIGraphicsGetCurrentContext();
  35. CGContextBeginPath(context);//标记
  36. CGContextMoveToPoint(context, _startPoint.x, _startPoint.y);
  37. CGContextAddLineToPoint(context,_middlePoint.x, _middlePoint.y);
  38. CGContextAddLineToPoint(context,_endPoint.x, _endPoint.y);
  39. CGContextClosePath(context);//路径结束标志,不写默认封闭
  40. [_color setFill]; //设置填充色
  41. [_color setStroke];//边框也设置为_color,否则为默认的黑色
  42. CGContextDrawPath(context, kCGPathFillStroke);//绘制路径path
  43. }
  44. @end