#import "YSGradientProgressBarView.h"
@interface YSGradientProgressBarView ()
@property (nonatomic,strong) UIBezierPath *circlePath;
@property (nonatomic,strong) CAShapeLayer *shapeLayer;
@property (nonatomic,assign) CGFloat line_width;
@end
@implementation YSGradientProgressBarView
- (instancetype)initWithFrame:(CGRect)frame{
if(self = [super initWithFrame:frame]){
CGFloat kwRate = 1.0;
BOOL isBigScreen = NO;
if (ZYSWidth>375 && ZYSHeight>812) {
isBigScreen = YES;
kwRate = ZYSKWRate;
}
self.line_width = 8*kwRate;
self.backgroundColor = [UIColor clearColor];
UIBezierPath *circlePath = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/2) radius:(self.frame.size.width - self.line_width)/2 startAngle:M_PI+M_PI/2 endAngle:M_PI*2+M_PI+M_PI/2 clockwise:YES];
self.circlePath = circlePath;
// 背景圆环
CAShapeLayer *bgLayer = [CAShapeLayer layer];
bgLayer.frame = self.bounds;
bgLayer.fillColor = [ZYSColor(0xFFFFFF ) colorWithAlphaComponent:0.2].CGColor;//圆环中间填充色
bgLayer.lineWidth = self.line_width;
bgLayer.strokeColor = ZYSColor(0x1D242F).CGColor;//圆环颜色
bgLayer.strokeStart = 0;
bgLayer.strokeEnd = 1;
bgLayer.lineCap = kCALineCapRound;
bgLayer.path = self.circlePath.CGPath;
[self.layer addSublayer:bgLayer];
}
return self;
}
-(void)createGradientProgressBarWithColors:(NSArray*)colors{
_shapeLayer = [CAShapeLayer layer];
_shapeLayer.frame = self.bounds;
_shapeLayer.fillColor = [UIColor clearColor].CGColor;
_shapeLayer.lineWidth = self.line_width;
_shapeLayer.lineCap = kCALineCapRound;
_shapeLayer.strokeColor = [UIColor blueColor].CGColor;
_shapeLayer.strokeStart = 0;
_shapeLayer.strokeEnd = 1.0;
_shapeLayer.path = self.circlePath.CGPath;
[self.layer addSublayer:_shapeLayer];
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
/** 从左到右的渐变色*/
CAGradientLayer *leftGradientLayer = [CAGradientLayer layer];
leftGradientLayer.frame = self.bounds;
[leftGradientLayer setColors:colors];
[leftGradientLayer setLocations:@[@(0.0),@(0.5f),@(1.0f)]];
[leftGradientLayer setStartPoint:CGPointMake(0, 1)];
[leftGradientLayer setEndPoint:CGPointMake(1, 1)];
[gradientLayer addSublayer:leftGradientLayer];
[gradientLayer setMask:_shapeLayer];
gradientLayer.frame = self.bounds;
[self.layer addSublayer:gradientLayer];
}
-(void)setGradientBarWithProgress:(float)progress{
self.shapeLayer.strokeEnd = progress;
}
ios 渐变色环型进度条
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...