gpt4 book ai didi

swift - 堆叠式进度指示器 swift

转载 作者:搜寻专家 更新时间:2023-11-01 06:17:25 29 4
gpt4 key购买 nike

我如何创建一个堆叠式进度指示器,以便与存储管理中的界面构建器一起使用?

enter image description here

有没有类似的cocoa控件?

如果没有,我是否应该尝试创建一个自定义 View ,在女巫中,每次我调用类似 progress.add(width: 10.0, color: NSColor(.. .))?

最佳答案

我刚刚做了一个绘制 View 的函数,你可以玩一下。

func drawStackedProgress(percentages:[Float], width:Float, height:Float, x:Float, y:Float){
var currentX = x

// I just threw a bunch of random (mostly probably ugly) colors in this array. Go ahead and make sure there's as many colors as stacked elements.
var colors = [UIColor.red, UIColor.blue, UIColor.green, UIColor.brown, UIColor.cyan]
var index = -1
for percentage in percentages{
index += 1
let DynamicView=UIView(frame: CGRect(x: CGFloat(currentX), y: CGFloat(y), width: CGFloat(Double(percentage)*Double(width)), height: CGFloat(height)))
currentX+=Float(Double(percentages[index])*Double(width))
DynamicView.backgroundColor=colors[index]
self.view.addSubview(DynamicView)
}

}

实现:

drawStackedProgress(percentages: [0.1,0.3,0.5,0.1], width: 200, height: 20, x: 200, y: 200)

关于swift - 堆叠式进度指示器 swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41494922/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com