ios 画圆环进度条
#import <UIKit/UIKit.h> @interface SNCircleProgressView : UIView
/**
* 进度值0-1.0之间
*/
@property (nonatomic,assign)CGFloat progressValue; /**
* 边宽
*/
@property(nonatomic,assign) CGFloat progressStrokeWidth; /**
* 进度条颜色
*/
@property(nonatomic,strong)UIColor *progressColor; /**
* 进度条轨道颜色
*/
@property(nonatomic,strong)UIColor *progressTrackColor; @end #import "SNCircleProgressView.h" @interface SNCircleProgressView ()
{ CAShapeLayer *backGroundLayer; //背景图层
CAShapeLayer *frontFillLayer; //用来填充的图层
UIBezierPath *backGroundBezierPath; //背景贝赛尔曲线
UIBezierPath *frontFillBezierPath; //用来填充的贝赛尔曲线 }
@end @implementation SNCircleProgressView
@synthesize progressColor = _progressColor;
@synthesize progressTrackColor = _progressTrackColor;
@synthesize progressValue = _progressValue;
@synthesize progressStrokeWidth = _progressStrokeWidth;
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
[self setUp];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame])
{
[self setUp]; }
return self; }
/**
* 初始化创建图层
*/
- (void)setUp
{
//创建背景图层
backGroundLayer = [CAShapeLayer layer];
backGroundLayer.fillColor = nil;
backGroundLayer.frame = self.bounds; //创建填充图层
frontFillLayer = [CAShapeLayer layer];
frontFillLayer.fillColor = nil;
frontFillLayer.frame = self.bounds; [self.layer addSublayer:backGroundLayer];
[self.layer addSublayer:frontFillLayer];
} - (void)setProgressColor:(UIColor *)progressColor
{
_progressColor = progressColor;
frontFillLayer.strokeColor = progressColor.CGColor;
}
- (UIColor *)progressColor
{
return _progressColor;
}
- (void)setProgressTrackColor:(UIColor *)progressTrackColor
{
_progressTrackColor = progressTrackColor;
backGroundLayer.strokeColor = progressTrackColor.CGColor;
backGroundBezierPath = [UIBezierPath bezierPathWithArcCenter:self.center radius:(CGRectGetWidth(self.bounds)-self.progressStrokeWidth)/.f startAngle: endAngle:M_PI*
clockwise:YES];
backGroundLayer.path = backGroundBezierPath.CGPath;
}
- (UIColor *)progressTrackColor
{
return _progressTrackColor;
}
- (void)setProgressValue:(CGFloat)progressValue
{
_progressValue = progressValue;
frontFillBezierPath = [UIBezierPath bezierPathWithArcCenter:self.center radius:(CGRectGetWidth(self.bounds)-self.progressStrokeWidth)/.f startAngle:-M_PI_4 endAngle:(*M_PI)*progressValue-M_PI_4 clockwise:YES];
frontFillLayer.path = frontFillBezierPath.CGPath;
}
- (CGFloat)progressValue
{
return _progressValue;
}
- (void)setProgressStrokeWidth:(CGFloat)progressStrokeWidth
{
_progressStrokeWidth = progressStrokeWidth;
frontFillLayer.lineWidth = progressStrokeWidth;
backGroundLayer.lineWidth = progressStrokeWidth;
}
- (CGFloat)progressStrokeWidth
{
return _progressStrokeWidth;
}
@end
#import "ViewController.h"
#import "SNCircleProgressView.h"
@interface ViewController ()
{
SNCircleProgressView *progressView;
}
@end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; progressView = [[SNCircleProgressView alloc]initWithFrame:CGRectMake(,, , )]; progressView.progressColor = [UIColor redColor];
progressView.progressStrokeWidth = .f;
progressView.progressTrackColor = [UIColor whiteColor]; [self.view addSubview:progressView]; [NSTimer scheduledTimerWithTimeInterval:.f target:self selector:@selector(changeProgressValue) userInfo:nil repeats:YES]; }
- (void)changeProgressValue
{
progressView.progressValue += 0.1;
if (progressView.progressValue>=.f) {
progressView.progressValue = 0.1f;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

ios 画圆环进度条的更多相关文章
- 用Raphael在网页中画圆环进度条
原文 :http://boytnt.blog.51cto.com/966121/1074215 条状的进度条我们见得太多了,实现起来比较简单,它总是长方形的,在方形的区域里摆 放就不太好看了.随着cs ...
- H5 可堆叠的圆环进度条,支持任意数量子进度条
by Conmajia SN: S22-W1M 由来 看到一篇帖子<vue实用组件--圆环百分比进度条>,让我想起了很多年前我在WinForm下仿制过的Chrome进度条. ▲ 原版进度条 ...
- iOS圆弧渐变进度条的实现
由于项目需要一个环形渐变进度条显示课程,这方便网上的确有很多相关资料但是,都是比较零散的而且,大多数只是放一堆代码就算完了.这里我想详细写一篇我自己实现这个进度条的过程. 实现一个圆弧进度条主要分为三 ...
- CSS3实现圆环进度条
摘要:圆环进度条被应用于各个场景,比如我们可以用来表示加载进度等.通常我们可以用 css3 的动画去实现. 详解 css3 实现圆环进度条 简单的画一个圆环,我们都知道如何使用 css 画一个圆环.( ...
- iOS学习-圆形进度条
效果: #import <UIKit/UIKit.h> @interface HsProfitRatePieWidgets : UIView { UILabel *_textLabel; ...
- 两种CSS3圆环进度条详解
晚上睡觉之前,我抽了1个多小时,研究了一下圆环进度条,结合从网上查阅的资料,我终于掌握了两种圆环的生成方法. 这次的效果就是单纯的CSS3效果,也没有写具体的JS,等以后有时间在好好整理一下吧~. 第 ...
- canvas绘制百分比圆环进度条
开发项目,PM会跟踪项目进度:完成某个事情,也可以设置一个完成的进度. 这里用canvas绘制一个简单百分比圆环进度条. 看下效果: 1. 动画方式 2. 静默方式 // 贴上代码,仅供参考 ...
- Xamarin iOS教程之进度条和滚动视图
Xamarin iOS教程之进度条和滚动视图 Xamarin iOS 进度条 进度条可以看到每一项任务现在的状态.例如在下载的应用程序中有进度条,用户可以很方便的看到当前程序下载了多少,还剩下多少.Q ...
- Vue/React圆环进度条
数据展示,一直是各行各业乐此不疲的需求,具体到前端开发行业,则是各种各种图表数据展示,各种表格数据展示,烦不胜烦(繁不胜繁)! 前几天刚做了折线图.柱状图.饼状图之类的图表数据展示效果,今天又碰到了类 ...
随机推荐
- TreeSet介绍
一.TreeSet原理: 1.TreeSet存储对象的时候, 可以排序, 但是需要指定排序的算法 2.Integer能排序(有默认顺序), String能排序(有默认顺序), 自定义的类存储的时候出现 ...
- 显示MYSQL数据库信息
显示所有的数据库:show databases 显示一个数据库所有表用:show tables from DatabaseName SELECT table_name FROM information ...
- Python输入输出(IO)
程序会有输入和输出,输入可以从标准输入或是从一个文件读入数据,程序的输出可以以一种友好可读的方式(human-readable)打印出来,或是写进一个文件,而标准输入和标准输出(键盘和显示器)在程序的 ...
- lght oj 1257 - Farthest Nodes in a Tree (II) (树dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1257 跟hdu2196一样,两次dfs //#pragma comment(l ...
- C#中的结构体与类的区别
经常听到有朋友在讨论C#中的结构与类有什么区别.正好这几日闲来无事,自己总结一下,希望大家指点. 1. 首先是语法定义上的区别啦,这个就不用多说了.定义类使用关键字class 定义结构使用关键字str ...
- Spring REST实践之安全
Securing REST Services 一般有六种方式实现的REST服务的安全: Session-based security HTTP Basic Authentication Digest ...
- session与缓存
分布式系统开发常见问题-1. session的复制与共享 2. 分布式缓存的设计 1. session的复制与共享 在web应用中,为了应对大规模访问,必须实现应用的集群部署.要实现集群部署主要需要实 ...
- MRI中T1和T2的含义与区分[转]
A. MRI名词解释 T1加权像.T2加权像为磁共振检查中报告中常提到的术语,很多非专业人士不明白是什么意思,要想认识何为T1加权像.T2加权像,请先了解几个基本概念: 1.磁共振(maget ...
- Linux 上的基础网络设备详解
抽象网络设备的原理及使用 网络虚拟化是 Cloud 中的一个重要部分.作为基础知识,本文详细讲述 Linux 抽象出来的各种网络设备的原理.用法.数据流向.您通过此文,能够知道如何使用 Linux 的 ...
- c++中获取代码运行时间
include<ctime> time_t begin,end; begin=clock(); { .............//被测试的代码 } end=clock(); cout ...