CircleView.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // CircleView.m
  3. // IBOSS
  4. //
  5. // Created by guan hong hou on 2018/6/22.
  6. // Copyright © 2018年 elongtian. All rights reserved.
  7. //
  8. #import "CircleView.h"
  9. @implementation CircleView
  10. - (id)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. [self setBackgroundColor:[UIColor whiteColor]];
  15. [self setNeedsDisplay];
  16. }
  17. return self;
  18. }
  19. /**
  20. * 画圆
  21. */
  22. -(void)drawRect:(CGRect)rect{
  23. // 1.获得上下文
  24. CGContextRef context = UIGraphicsGetCurrentContext();
  25. //画圆
  26. CGContextSetFillColorWithColor(context,[UIColor hexColor:@"6acb9a"].CGColor);//填充颜色
  27. CGContextAddArc(context,80, 80, 60, 0, 2*M_PI, 0); //添加一个圆
  28. CGContextDrawPath(context, kCGPathFill); //填充路径
  29. CGContextRef context1 = UIGraphicsGetCurrentContext();
  30. CGContextSetLineWidth(context1,5);
  31. UIColor *lineColor = [UIColor hexColor:@"fecb6e"];
  32. CGContextSetStrokeColorWithColor(context1, lineColor.CGColor);//线框颜色
  33. //画圆
  34. double arc= M_PI*2*([_completePercent doubleValue]/100);
  35. CGContextAddArc(context1, 80, 80,62,M_PI/2*3 ,M_PI/2*3+arc, NO);
  36. //渲染
  37. CGContextStrokePath(context);
  38. }
  39. @end