demo下载地址:https://github.com/haozheMa/LoopProgressDemo/tree/master

ViewController中的代码

  1. #import "ViewController.h"
  2. #import "ProgressView.h"
  3.  
  4. @interface ViewController ()
  5.  
  6. @property (strong, nonatomic) UISlider *progressSlider;
  7.  
  8. @property (strong, nonatomic) ProgressView *progressView;
  9.  
  10. @end
  11.  
  12. @implementation ViewController
  13.  
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. _progressView = [[ProgressView alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width/2 - 80, 100, 160, 160)];
  17. [self.view addSubview:_progressView];
  18. _progressSlider = [[UISlider alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-80, 400, 160, 10)];
  19. [_progressSlider addTarget:self action:@selector(sliderChange) forControlEvents:UIControlEventValueChanged];
  20. _progressSlider.maximumValue = 1.0;
  21. _progressSlider.minimumValue = 0.0;
  22. [self.view addSubview:_progressSlider];
  23. }
  24.  
  25. -(void)sliderChange
  26. {
  27. _progressView.percentage = _progressSlider.value;
  28. }
  29.  
  30. @end

ProgressView中的代码

  1. .h
  2.  
  3. #import <UIKit/UIKit.h>
  4.  
  5. @interface ProgressView : UIView
  6.  
  7. @property(assign, nonatomic)CGFloat percentage;
  8.  
  9. @end
  10.  
  11. .m
  12.  
  13. #import "ProgressView.h"
  14.  
  15. @interface ProgressView ()
  16.  
  17. @property (strong,nonatomic) UILabel *label;
  18.  
  19. @end
  20.  
  21. @implementation ProgressView
  22.  
  23. -(instancetype)initWithFrame:(CGRect)frame
  24. {
  25. self = [super initWithFrame:frame];
  26. if (self) {
  27. self.percentage = 0.0;
  28. self.backgroundColor = [UIColor whiteColor];
  29. [self loadSubviews];
  30. }
  31. return self;
  32. }
  33.  
  34. -(void)loadSubviews
  35. {
  36. _label = [[UILabel alloc] initWithFrame:CGRectMake(10, self.frame.size.height/2 - 10, self.frame.size.width - 20, 20)];
  37. _label.textAlignment = NSTextAlignmentCenter;
  38. _label.font = [UIFont systemFontOfSize:12];
  39. _label.textColor = [UIColor blackColor];
  40. [self addSubview:_label];
  41. }
  42.  
  43. -(void)setPercentage:(CGFloat)percentage
  44. {
  45. _percentage = percentage;
  46. _label.text = [NSString stringWithFormat:@"%.2f%%",_percentage*100];
  47. [self setNeedsDisplay];
  48. }
  49.  
  50. -(void)drawRect:(CGRect)rect
  51. {
  52. CGContextRef contextRef = UIGraphicsGetCurrentContext();
  53. CGSize viewSize = self.bounds.size;
  54. CGPoint center = CGPointMake(viewSize.width/2, viewSize.height/2);
  55. CGFloat radius = viewSize.width/2;
  56. CGContextBeginPath(contextRef);
  57. CGContextMoveToPoint(contextRef, center.x, center.y);
  58. CGContextAddArc(contextRef, center.x, center.y, radius, - M_PI_2, 2*M_PI*_percentage - M_PI_2, 0);
  59. CGContextSetFillColorWithColor(contextRef, [UIColor redColor].CGColor);
  60. CGContextFillPath(contextRef);
  61.  
  62. //填充圆,无边框
  63. CGContextAddArc(contextRef, center.x, center.y, radius - 10, 0, 2*M_PI, 0); //添加一个圆
  64. CGContextSetFillColorWithColor(contextRef, [UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1].CGColor);
  65. CGContextClosePath(contextRef);
  66. CGContextDrawPath(contextRef, kCGPathFill);//绘制填充
  67. CGContextStrokePath(contextRef);//绘画路径
  68. }

iOS 简易环形进度条的更多相关文章

  1. iOS 开发技巧-制作环形进度条

    有几篇博客写到了怎么实现环形进度条,大多是使用Core Graph来实现,实现比较麻烦且效率略低,只是一个小小的进度条而已,我们当然是用最简单而且效率高的方式来实现. 先看一下这篇博客,博客地址:ht ...

  2. iOS一分钟学会环形进度条

    有几篇博客写到了怎么实现环形进度条,大多是使用Core Graph来实现,实现比较麻烦且效率略低,只是一个小小的进度条而已,我们当然是用最简单而且效率高的方式来实现.先看一下这篇博客,博客地址:htt ...

  3. iOS带动画的环形进度条(进度条和数字同步)

    本篇写的是实现环形进度条,并带动画效果,要实现这些,仅能通过自己画一个 方法直接看代码 为了方便多次调用,用继承UIView的方式 .m文件 #import <UIKit/UIKit.h> ...

  4. Android简易实战教程--第十七话《自定义彩色环形进度条》

    转载请注明出处:http://blog.csdn.net/qq_32059827/article/details/52203533   点击打开链接 在Android初级教程里面,介绍了shape用法 ...

  5. iOS 环形进度条

    .h文件 #import <UIKit/UIKit.h> @interface YTProgressView : UIView@property (nonatomic, copy) NSS ...

  6. [Swift通天遁地]一、超级工具-(2)制作美观大方的环形进度条

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  7. 图解CSS3制作圆环形进度条的实例教程

    圆环形进度条制作的基本思想还是画出基本的弧线图形,然后CSS3中我们可以控制其旋转来串联基本图形,制造出部分消失的效果,下面就来带大家学习图解CSS3制作圆环形进度条的实例教程 首先,当有人说你能不能 ...

  8. Swift - 环形进度条(UIActivityIndicatorView)的用法

    Swift中,除了条形进度条外,还有环形进度条,效果图如下: 1,环形进度条的基本属性 (1)Style: Large White:比较大的白色环形进度条 White:白色环形进度条 Gray:灰色环 ...

  9. 环形进度条的实现方法总结和动态时钟绘制(CSS3、SVG、Canvas)

    缘由: 在某一个游戏公司的笔试中,最后一道大题是,“用CSS3实现根据动态显示时间和环形进度[效果如下图所示],且每个圆环的颜色不一样,不需要考虑IE6~8的兼容性”.当时第一想法是用SVG,因为SV ...

随机推荐

  1. 简单的git入门介绍及常用操作

    集中式版本控制系统采用中央服务器上存储的所有文件和实现团队协作.但是CVCS主要缺点是中央服务器的单点故障,即故障.不幸的是,如果中央服务器宕机一小时,然后在该时段没有人可以合作.即使在最坏的情况下, ...

  2. UIKit控件直接显示网页文字内容

    NSString *html = @"<bold>Hello</bold> Now<br> <em>iOS</em> can cr ...

  3. GCD应用场景

    1.计算文件大小放在子线程中中计算,计算完了,回到主线程更新UI

  4. 关于html5的几个新标签在IE9之前不支持的解决办法

    IE8及之前的浏览器不支持用CSS的方法来使用这些尚未支持的结构元素,为了在Internet Explorer浏览器中也能正常使用这些结构元素,需要使用JavaScript脚本,如下:<scri ...

  5. JS定时器的使用--无缝滚动

    <title>无标题文档</title> <style> * {margin:0; padding:0;} #div1{width:1172px; height:2 ...

  6. 【转载】关于SetWindowOrgEx、SetViewportOrgEx、SetViewportExtEx 和SetWindowExtEx 详解

    关于SetWindowOrgEx.SetViewportOrgEx.SetViewportExtEx 和SetWindowExtEx 详解 1.  SetWindowOrgEx是设置窗口的原点坐标. ...

  7. HDU4325--Flowers--树状数组,离散化

    Description As is known to all, the blooming time and duration varies between different kinds of flo ...

  8. InnoDB的数据页结构

    页是InnoDB存储引擎管理数据库的最小磁盘单位.页类型为B-tree node的页,存放的即是表中行的实际数据了. InnoDB数据页由以下七个部分组成,如图所示: File Header(文件头) ...

  9. asp.net MVC 3多语言方案--再次写, 配源码

    之前写了一篇asp.net MVC多语言方案,那次其实是为American Express银行开发的.有许多都是刚开始接触,对其也不太熟悉.现在再回过头去看,自己做一个小网站,完全用asp.net m ...

  10. 9、外观模式(Facade)

    外观模式是为了解决类与类之家的依赖关系的,像spring一样,可以将类和类之间的关系配置到配置文件中,而外观模式就是将他们的关系放在一个Facade类中,降低了类类之间的耦合度,该模式中没有涉及到接口 ...