分段分颜色环形进度条
来源:互联网 发布:百度 程序员 签字费 编辑:程序博客网 时间:2024/06/07 09:03
分段划曲线
思路
将第一段的终值赋值给第二段的初始值,以此类推。。。2.[self setNeedsDisplay]更新画图进度
代码示例
/* 显示多段不同比例的进度 */#import <UIKit/UIKit.h>#import "HXProgressColorAndRateModel.h"@interface PieProgressView : UIView@property(nonatomic,strong) NSMutableArray *colors;//显示对应的进度和颜色,模型数组@property(nonatomic,strong) UIColor *defaultColor;//只有一种颜色的时候的显示-(void)setProgressWithAnimated;@end#import "PieProgressView.h"#import <QuartzCore/QuartzCore.h>@interface PieProgressView()@property(nonatomic,assign) float start;@property(nonatomic,assign) float end;@end@implementation PieProgressView-(void)drawRect:(CGRect)rect{ /* 不断将end赋值给start,划线 */ CGContextRef context = UIGraphicsGetCurrentContext(); self.start = -M_PI_2; CGPoint point = CGPointMake(self.frame.size.width/2, self.frame.size.height/2);//中心位置 if (self.colors&&self.colors.count) { for (int i=0; i<self.colors.count; i++) { HXProgressColorAndRateModel *model = self.colors[i]; self.end=self.start + model.progressRate*2*M_PI; CGFloat endAngle = self.end; float radiusCircle = self.frame.size.width>self.frame.size.height?self.frame.size.height/2:self.frame.size.width/2; UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:point radius:(radiusCircle-2) startAngle:self.start endAngle:endAngle clockwise:YES]; CGContextSetLineCap(context, kCGLineCapSquare); CGContextSetLineWidth(context, 4.0); CGContextSetStrokeColorWithColor(context, model.progressColor.CGColor);//部分颜色 CGContextAddPath(context, bezierPath.CGPath); CGContextStrokePath(context);//渲染 self.start = self.end; } }else{//只有一种颜色时候 CGFloat endAngle = 2*M_PI; float radiusCircle = self.frame.size.width>self.frame.size.height?self.frame.size.height/2:self.frame.size.width/2; UIBezierPath *bezierPath = [UIBezierPath bezierPathWithArcCenter:point radius:(radiusCircle-2) startAngle:self.start endAngle:endAngle clockwise:YES]; CGContextSetLineCap(context, kCGLineCapSquare); CGContextSetLineWidth(context, 4.0); //防止不赋值时候为黑色。。。 UIColor *deColor = self.defaultColor?self.defaultColor:[UIColor whiteColor]; CGContextSetStrokeColorWithColor(context, deColor.CGColor);//第一部分颜色 CGContextAddPath(context, bezierPath.CGPath); CGContextStrokePath(context);//渲染 }}-(void)setProgressWithAnimated{ self.hidden = NO; [self setNeedsDisplay];//调用drawRect方法}
0 0
- 分段分颜色环形进度条
- Android环形颜色渐变进度条
- 环形进度条
- 环形进度条
- android 环形进度条 圆形
- android实现环形进度条
- 自定义环形进度条
- Android自定义环形进度条
- CAShapeLayer绘制环形进度条
- js生成环形进度条
- 环形进度条CircleProgress
- android 自定义 环形进度条
- Android seekBar2.环形进度条
- 自定义环形进度条
- canvas实现环形进度条
- Axure画环形进度条
- Android 环形进度条Demo
- NGUI特效--环形进度条
- jsp中include指令和include动作区别
- C++作业3-1 3 4
- 线程池ExecutorService的submit和execute
- php将十六进制颜色值转换为十进制
- 二叉树之一BST树,AVL树详解及B树和红黑树原理分析
- 分段分颜色环形进度条
- c++中异常的处理机制
- Spring并发访问的线程安全性问题
- Hexo 添加百度统计
- android Activity切换屏 生命周期变化问题
- php学习之五(面向对象)
- 我的第一次Unity游戏开发历程
- maven快照版本和发布版本
- c++中的函数模版