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

ViewController中的代码

#import "ViewController.h"
#import "ProgressView.h" @interface ViewController () @property (strong, nonatomic) UISlider *progressSlider; @property (strong, nonatomic) ProgressView *progressView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
_progressView = [[ProgressView alloc] initWithFrame:CGRectMake([[UIScreen mainScreen] bounds].size.width/2 - 80, 100, 160, 160)];
[self.view addSubview:_progressView];
_progressSlider = [[UISlider alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2-80, 400, 160, 10)];
[_progressSlider addTarget:self action:@selector(sliderChange) forControlEvents:UIControlEventValueChanged];
_progressSlider.maximumValue = 1.0;
_progressSlider.minimumValue = 0.0;
[self.view addSubview:_progressSlider];
} -(void)sliderChange
{
_progressView.percentage = _progressSlider.value;
} @end

ProgressView中的代码

.h

#import <UIKit/UIKit.h>

@interface ProgressView : UIView

@property(assign, nonatomic)CGFloat percentage;

@end

.m

#import "ProgressView.h"

@interface ProgressView ()

@property (strong,nonatomic) UILabel *label;

@end

@implementation ProgressView

-(instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.percentage = 0.0;
self.backgroundColor = [UIColor whiteColor];
[self loadSubviews];
}
return self;
} -(void)loadSubviews
{
_label = [[UILabel alloc] initWithFrame:CGRectMake(10, self.frame.size.height/2 - 10, self.frame.size.width - 20, 20)];
_label.textAlignment = NSTextAlignmentCenter;
_label.font = [UIFont systemFontOfSize:12];
_label.textColor = [UIColor blackColor];
[self addSubview:_label];
} -(void)setPercentage:(CGFloat)percentage
{
_percentage = percentage;
_label.text = [NSString stringWithFormat:@"%.2f%%",_percentage*100];
[self setNeedsDisplay];
} -(void)drawRect:(CGRect)rect
{
CGContextRef contextRef = UIGraphicsGetCurrentContext();
CGSize viewSize = self.bounds.size;
CGPoint center = CGPointMake(viewSize.width/2, viewSize.height/2);
CGFloat radius = viewSize.width/2;
CGContextBeginPath(contextRef);
CGContextMoveToPoint(contextRef, center.x, center.y);
CGContextAddArc(contextRef, center.x, center.y, radius, - M_PI_2, 2*M_PI*_percentage - M_PI_2, 0);
CGContextSetFillColorWithColor(contextRef, [UIColor redColor].CGColor);
CGContextFillPath(contextRef); //填充圆,无边框
CGContextAddArc(contextRef, center.x, center.y, radius - 10, 0, 2*M_PI, 0); //添加一个圆
CGContextSetFillColorWithColor(contextRef, [UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1].CGColor);
CGContextClosePath(contextRef);
CGContextDrawPath(contextRef, kCGPathFill);//绘制填充
CGContextStrokePath(contextRef);//绘画路径
}

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. Hibernate 系列教程4-单向多对一

    项目图片 hibernate.cfg.xml <mapping resource="com/jege/hibernate/one/way/manytoone/User.hbm.xml& ...

  2. oracle_一次移动数据库dbf文件的操作

    oracle数据库的dbf路径下面磁盘不足,需要把原始路径下面的dbf文件移动到另外一个磁盘路径下, 具体的操作有四步. 1.把整个表空间offline. 2.copy原始路径下的dbf文件到新的路径 ...

  3. JMeter-使用Badboy录制Web测试脚本

    JMeter是纯Java编写的软件功能和性.能测试工具,其录制脚本过于笨拙和复杂.而Badboy是用C++开发的动态应用测试工具,其拥有强大的屏幕录制和回放功能,同时提供图形结果分析功能,刚好弥补了J ...

  4. Ubuntu + Django + Nginx + uwsgi

    环境 Ubuntu 14.04 Python 2.7 Django 1.8.4 1 安装Nginx     sudo apt-get install nginx 测试  sudo /etc/init. ...

  5. HDU 1814 Peaceful Commission

    2-SAT,输出字典序最小的解,白书模板. //TwoSAT输出字典序最小的解的模板 //注意:0,1是一组,1,2是一组..... #include<cstdio> #include&l ...

  6. HDU 5900

    QSC and Master Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  7. 在数据库里面有这么一个表:用m代表男,用f代表女,现在我要输出格式为中文的:男和女,sql语句该怎么写

    在数据库里面有这么一个表:用m代表男,用f代表女,现在我要输出格式为中文的:男和女, sql语句该怎么写 select  case sex when 'm' then '男' else '女'   a ...

  8. zf-关于荆州图片链接和弹出页面问题

    target="_blank" 属性不能写在div 里 所以我在里面加了个a标签 这个属性的作用就是弹出一个新的页面,不会在原先的页面上换地址 如果 style 的加载图片卸载cs ...

  9. over-float清除浮动

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  10. SDAU课程练习--problemE

    problemE 题目描述 "今年暑假不AC?" "是的." "那你干什么呢?" "看世界杯呀,笨蛋!" "@ ...