iOS 开发之环形倒计时进度条(虚线/实线)

摘要:
代码非常简单。这是顺时针方向。如果要逆时针旋转,则需要将顺时针旋转更改为0,还需要更改起始角度和结束角度。源代码地址:https://github.com/LfyDragon/CountDown直接代码:-(void)drawRect:(CGRect)rect{CAShapeLayer*shapeLayer=[CAShapeLayeer];shapeLayer.frame=self.boun

代码很简单,一看便知。这里为顺时针,若想要逆时针,clockwise改为0,还需更改起始角度和终点角度。

源码地址:https://github.com/LfyDragon/CountDown

直接上代码:- (void)drawRect:(CGRect)rect {

    
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    shapeLayer.frame = self.bounds;
    UIBezierPath *path = [UIBezierPath bezierPathWithArcCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/2) radius:self.frame.size.height/2 startAngle:-M_PI_2 endAngle:M_PI*3/2 clockwise:1];
    shapeLayer.path = path.CGPath;
    shapeLayer.fillColor = [UIColor clearColor].CGColor;
    shapeLayer.lineWidth = 10.0f;
    
    if ([self.flag isEqualToString:@"track"]) {
        shapeLayer.strokeColor = [UIColor colorWithRed:146/255.0f green:146/255.0f blue:146/255.0f alpha:1].CGColor;
    } else{
        shapeLayer.strokeColor = [UIColor colorWithRed:61/255.0f green:191/255.0f blue:135/255.0f alpha:1].CGColor;
    }
    
    //每个虚线长度为2,间隔为3   这句设置线条为虚线,去掉即为实线
shapeLayer.lineDashPattern = [NSArray arrayWithObjects:[NSNumber numberWithInt:2], [NSNumber numberWithInt:3], nil]; [self.layer addSublayer:shapeLayer]; if ([self.flag isEqualToString:@"process"]) { CABasicAnimation *pathAnima = [CABasicAnimation animationWithKeyPath:@"strokeEnd"]; pathAnima.duration = self.time; pathAnima.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear]; pathAnima.fromValue = [NSNumber numberWithFloat:0.0f]; pathAnima.toValue = [NSNumber numberWithFloat:1.0f]; pathAnima.fillMode = kCAFillModeForwards; pathAnima.removedOnCompletion = NO; [shapeLayer addAnimation:pathAnima forKey:@"strokeEndAnimation"]; } }

随手截个图:

iOS 开发之环形倒计时进度条(虚线/实线)第1张

免责声明:文章转载自《iOS 开发之环形倒计时进度条(虚线/实线)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇招聘java工程师openlayers集成到vue开发下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

Sobel算子 (转)

幻灯片1 Sobel算子幻灯片2 I Sobel边缘检测算子l在讨论边缘算子之前,我们首先给出一些术语的定义:l边缘:信息的突然变化,如灰度级或结构。边缘是一个区域的结束,另一个区域开始。此功能可用于分割图像。Sobel算子也是一种梯度幅度,即偏导数Sx和Sy可以通过卷积模板实现。...

vant-picker二次封装

痛点在项目经常会遇到这样的设计,下拉选择框,在vant中没有提供直接的select组件,但是可以使用Field、Popup和Picker这三个组件组合来完成。this.show;}},watch:{selectValue:function{this.result=newVal;},result{this.$emit;}}};效果链接:https://www....

Flutter——数组以符号隔开转字符串

///数组转换为字符串StringgetTaskScreen(Listlist){ListtempList=List();Stringstr='';List.forEach((f){tempList.add(f.title);});临时列表。forEach((f){if(str==“”){str=“$f”;}否则{str=“$str”,“$f”;}});re...

echarts折线图 鼠标移入改变小点显示样式

=undefined){res+=nameList[i].seriesName+':'+nameList[i].data+'%'+''}}res=res.split;returnres[0]+''+res[1];}}echarts折线图的鼠标移动上去小点显示样式修改tooltip:{trigger:'axis',formatter:function{varr...

PX4 飞控源码系统框架介绍

该部分主要是PX4系统的使用的所有的数据结构的集合部分,各种任务和sensor驱动中需要获取的sensor数据都在此部分,还包含各种运行状态的数据结构。...

TensorRT在ubuntu18.04的安装

安装TensorRT前需要安装Cuda和cudnn,安装步骤可以参考ubuntu安装cuda和cudnn。...