xcode – 在SWIFT中绘制循环段进度
发布时间:2020-12-15 01:41:46 所属栏目:百科 来源:网络整理
导读:我想用切片创建一个循环进度,其中每个切片都是一个弧. 我的代码基于这个答案: Draw segments from a circle or donut 但我不知道如何复制它并旋转10次. 我想按照进度变量(百分比)对其进行着色. 编辑:我想要这样的东西 请帮忙 问候 解决方法 您可以使用循循
我想用切片创建一个循环进度,其中每个切片都是一个弧.
我的代码基于这个答案: 但我不知道如何复制它并旋转10次. 编辑:我想要这样的东西 请帮忙 问候 解决方法
您可以使用循循环径并设置strokeStart和StrokeEnd.像这样的东西:
let circlePath = UIBezierPath(ovalInRect: CGRect(x: 200,y: 200,width: 150,height: 150)) var segments: [CAShapeLayer] = [] let segmentAngle: CGFloat = (360 * 0.125) / 360 for var i = 0; i < 8; i++ { let circleLayer = CAShapeLayer() circleLayer.path = circlePath.CGPath // start angle is number of segments * the segment angle circleLayer.strokeStart = segmentAngle * CGFloat(i) // end angle is the start plus one segment,minus a little to make a gap // you'll have to play with this value to get it to look right at the size you need let gapSize: CGFloat = 0.008 circleLayer.strokeEnd = circleLayer.strokeStart + segmentAngle - gapSize circleLayer.lineWidth = 10 circleLayer.strokeColor = UIColor(red:0,green:0.004,blue:0.549,alpha:1).CGColor circleLayer.fillColor = UIColor.clearColor().CGColor // add the segment to the segments array and to the view segments.insert(circleLayer,atIndex: i) view.layer.addSublayer(segments[i]) } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |