#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 画圆环进度条的更多相关文章

  1. 用Raphael在网页中画圆环进度条

    原文 :http://boytnt.blog.51cto.com/966121/1074215 条状的进度条我们见得太多了,实现起来比较简单,它总是长方形的,在方形的区域里摆 放就不太好看了.随着cs ...

  2. H5 可堆叠的圆环进度条,支持任意数量子进度条

    by Conmajia SN: S22-W1M 由来 看到一篇帖子<vue实用组件--圆环百分比进度条>,让我想起了很多年前我在WinForm下仿制过的Chrome进度条. ▲ 原版进度条 ...

  3. iOS圆弧渐变进度条的实现

    由于项目需要一个环形渐变进度条显示课程,这方便网上的确有很多相关资料但是,都是比较零散的而且,大多数只是放一堆代码就算完了.这里我想详细写一篇我自己实现这个进度条的过程. 实现一个圆弧进度条主要分为三 ...

  4. CSS3实现圆环进度条

    摘要:圆环进度条被应用于各个场景,比如我们可以用来表示加载进度等.通常我们可以用 css3 的动画去实现. 详解 css3 实现圆环进度条 简单的画一个圆环,我们都知道如何使用 css 画一个圆环.( ...

  5. iOS学习-圆形进度条

    效果: #import <UIKit/UIKit.h> @interface HsProfitRatePieWidgets : UIView { UILabel *_textLabel; ...

  6. 两种CSS3圆环进度条详解

    晚上睡觉之前,我抽了1个多小时,研究了一下圆环进度条,结合从网上查阅的资料,我终于掌握了两种圆环的生成方法. 这次的效果就是单纯的CSS3效果,也没有写具体的JS,等以后有时间在好好整理一下吧~. 第 ...

  7. canvas绘制百分比圆环进度条

    开发项目,PM会跟踪项目进度:完成某个事情,也可以设置一个完成的进度. 这里用canvas绘制一个简单百分比圆环进度条. 看下效果: 1. 动画方式   2. 静默方式   // 贴上代码,仅供参考 ...

  8. Xamarin iOS教程之进度条和滚动视图

    Xamarin iOS教程之进度条和滚动视图 Xamarin iOS 进度条 进度条可以看到每一项任务现在的状态.例如在下载的应用程序中有进度条,用户可以很方便的看到当前程序下载了多少,还剩下多少.Q ...

  9. Vue/React圆环进度条

    数据展示,一直是各行各业乐此不疲的需求,具体到前端开发行业,则是各种各种图表数据展示,各种表格数据展示,烦不胜烦(繁不胜繁)! 前几天刚做了折线图.柱状图.饼状图之类的图表数据展示效果,今天又碰到了类 ...

随机推荐

  1. Skeletal Animation

    [Skeletal Animation] Skeletal animation is the use of “bones” to animate a model. The movement of bo ...

  2. McAfee Host Intrusion Prevention

    McAfee Host Intrusion Prevention是一款集防火墙功能和HIPS于一身的主动防御和防火墙软件,将其与 McAfee VirusScan Enterprise 8.5/8.7 ...

  3. 在ASP.NET MVC中验证checkbox 必须选中 (Validation of required checkbox in Asp.Net MVC)

    转载自 http://blog.degree.no/2012/03/validation-of-required-checkbox-in-asp-net-mvc/ Why would you want ...

  4. C# Devexpress学习--LabelControl

    A LabelControl can display an image (regular or animated GIF file). Different images can be provided ...

  5. C# Control 控件DrapDrop不触发的问题

    今天在做一个鼠标拖拽功能时,需要用到PictureBox的拖拽,即拖拽一个图标到PictureBox上实现加载绘制,可是怎么整也触发不了DrapDrop事件,最后终于找到了解决方法:原来需要在Drog ...

  6. QT输入输出(一) 之 QDataStream 测试

    QT提供了两个高级别的流类---QDataStream和QTextStream,可以从任意的输入输出设备读取或写入数据. QDataStream用于读写二进制数据,它的优点是:在读写数据的时候已经严格 ...

  7. iOS开发-HTTP请求

    什么是URL?URL就是资源的地址.位置,互联网上的每个资源都有一个唯一的URLURL的基本格式: URL中常见的协议 (1)HTTP 超文本传输协议,访问的是远程的网络资源,格式是http:// h ...

  8. HTML第九天学习笔记

    今天就继续看了下浮点float属性,代码如下: <html> <head> <title>CSS float属性</title> <meta ht ...

  9. 一些关于Block, ARC, GCD的总结

    基础解释不做.基础的东西链接如下: 1. Block:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Bl ...

  10. 【转】Android 属性动画(Property Animation) 完全解析 (上)

    http://blog.csdn.net/lmj623565791/article/details/38067475 1.概述 Android提供了几种动画类型:View Animation .Dra ...