有几篇博客写到了怎么实现环形进度条,大多是使用Core Graph来实现,实现比较麻烦且效率略低,只是一个小小的进度条而已,我们当然是用最简单而且效率高的方式来实现。
先看一下这篇博客,博客地址:http://www.brighttj.com/ios/ios-implement-loop-progress.html
这篇博客写的不错,不过看上去还是略微复杂了,我自己根据自己的思路整理了一下,当然目的是为了更加简洁易懂。

一:先制作一个不带颜色渐变的进度条

自定义一个cycleView,在.m 中实现drawRect方法

 1 - (void)drawRect:(CGRect)rect {
 2 
 3     CGContextRef ctx = UIGraphicsGetCurrentContext();//获取上下文
 4 
 5     CGPoint center = CGPointMake(100, 100);  //设置圆心位置
 6     CGFloat radius = 90;  //设置半径
 7     CGFloat startA = - M_PI_2;  //圆起点位置
 8     CGFloat endA = -M_PI_2 + M_PI * 2 * _progress;  //圆终点位置
 9 
10     UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:center radius:radius startAngle:startA endAngle:endA clockwise:YES];
11 
12     CGContextSetLineWidth(ctx, 10); //设置线条宽度
13     [[UIColor blueColor] setStroke]; //设置描边颜色
14 
15     CGContextAddPath(ctx, path.CGPath); //把路径添加到上下文
16 
17     CGContextStrokePath(ctx);  //渲染
18 
19 }
View Code

相关文章:

  • 2021-09-19
  • 2021-09-23
  • 2021-06-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
  • 2022-02-05
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案