基本上,我想创建一个自定义进度视图,它将根据进度值具有不同的颜色。 它应如下所示:
[----- ----红色] [ - 黄色 - ] [ - 绿色 - ]
答案 0 :(得分:2)
答案 1 :(得分:0)
1)在某些图像编辑程序中创建具有所需颜色渐变的图像。
2)将图片放入资产库。
3)从相应的图像生成UIImage实例。
UIImage *image = [UIImage imageNamed:@"imageName"];
4)将UIImage实例分配给UIProgressView的progressImage
属性。
self.progressView. progressImage = image;
答案 2 :(得分:0)
雨燕5
我的方法是这样,希望对您有所帮助。我将4个progres条形图堆叠在一起,并堆叠在stackView中。
struct statsData {
var number: Int
var name: String
var color: UIColor
}
var data: [statsData] = []
data += [statsData(number: participants.filter{ $0.CATEGORY == "yde"}.count, name: "young", color: #colorLiteral(red: 0.02044569142, green: 0.5364668965, blue: 0.7812533975, alpha: 1)), statsData(number: participants.filter{ $0.CATEGORY == "del"}.count, name: "Delegate", color: #colorLiteral(red: 0.01050937176, green: 0.2793724537, blue: 0.4485790133, alpha: 1)), statsData(number: participants.filter{ $0.CATEGORY == "spk"}.count, name: "Speaker", color: #colorLiteral(red: 0.7677220702, green: 0.6388614774, blue: 0.03215418011, alpha: 1)), statsData(number: participants.filter{ $0.CATEGORY == "acc"}.count, name: "Companion", color: #colorLiteral(red: 0.9999409318, green: 0.5844026208, blue: 0.5724465251, alpha: 1))]
func percentageBar(){
data = data.sorted{ $0.number < $1.number }
// Front
Bar0.transform = CGAffineTransform(scaleX: 1, y: 3)
Bar0.layer.cornerRadius = 4
Bar0.clipsToBounds = true
Bar0.progress = Float(100.0 / Float(total) * Float(data[0].number))/100
Bar0.tintColor = data[0].color
Bar1.transform = CGAffineTransform(scaleX: 1, y: 3)
Bar1.layer.cornerRadius = 4
Bar1.clipsToBounds = true
Bar1.progress = Float(100.0 / Float(total) * Float(data[0].number + data[1].number))/100
Bar1.tintColor = data[1].color
Bar2.transform = CGAffineTransform(scaleX: 1, y: 3)
Bar2.layer.cornerRadius = 4
Bar2.clipsToBounds = true
Bar2.progress = Float(100.0 / Float(total) * Float(data[0].number + data[1].number + data[2].number))/100
Bar2.tintColor = data[2].color
// Back
Bar3.transform = CGAffineTransform(scaleX: 1, y: 3)
Bar3.layer.cornerRadius = 4
Bar3.clipsToBounds = true
Bar3.layer.sublayers![1].cornerRadius = 4
Bar3.subviews[1].clipsToBounds = true
Bar3.progress = Float(100.0 / Float(total) * Float(data[0].number + data[1].number + data[2].number + data[3].number))/100
Bar3.tintColor = data[3].color
}