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圆环进度条
数据展示,一直是各行各业乐此不疲的需求,具体到前端开发行业,则是各种各种图表数据展示,各种表格数据展示,烦不胜烦(繁不胜繁)! 前几天刚做了折线图.柱状图.饼状图之类的图表数据展示效果,今天又碰到了类 ...
随机推荐
- Linux下的cut选取命令详解
定义 正如其名,cut的工作就是“剪”,具体的说就是在文件中负责剪切数据用的.cut是以每一行为一个处理对象的,这种机制和sed是一样的 剪切依据 cut命令主要是接受三个定位方法: 第一,字节(by ...
- win7 文件共享 xp
前几天因为需要将win7内一文件夹共享给XP使用,因为NT5跟NT6安全机制的问题,共享的实现没有XP共享的方便,很多人是牺牲(关闭)了win7的系统防火墙才达到共享给XP的目的,但是关闭防火墙势必会 ...
- Codeforces 600 E. Lomsat gelral (dfs启发式合并map)
题目链接:http://codeforces.com/contest/600/problem/E 给你一棵树,告诉你每个节点的颜色,问你以每个节点为根的子树中出现颜色次数最多的颜色编号和是多少. 最容 ...
- 用vagrant搭建一个自己的lnmp环境(一)
用vagrant搭建自己的lnmp环境 1.工具: a.vagrant b.virtual box c.linux服务器box(此处我使用centos 7.0) 2.安装完vagrant和virtua ...
- So many good projects for studying C programming lanuage.
Some one asked a question for studying C programming language on stackexachange.com. He got a bucket ...
- 窥探EasyMock(2)进阶使用篇
from:http://www.iteye.com/topic/310313 1. 生成 Mock 对象 如何创建一个需要严格遵守调用顺序的mock对象? SomeInterface mockObj ...
- Extjs Google的Suggest的自动提示 从后台取数据
//服务器取数据 var remoteStore = Ext.create('Ext.data.Store', { proxy: ({ type: "ajax", url:&quo ...
- (5)html表单
本节解说: html的表单. form * <form> 标签用于为用户输入创建 HTML 表单. 表单能够包含 input 元素,比如文本字段.复选框.单选框.提交按钮等等. * < ...
- uva331 - Mapping the Swaps
Mapping the Swaps Sorting an array can be done by swapping certain pairs of adjacent entries in the ...
- 读loadBalance技术的一些笔记
以前知道loadbalance的原理,但是仅仅是浅浅的了解过,今天看了一篇 10多年前 一位大神级别人物 写的文章 顿时学习了 http://www.linuxvirtualserver.org/zh ...