如何在 UIProgressView 中设置进度色调颜色

Posted

技术标签:

【中文标题】如何在 UIProgressView 中设置进度色调颜色【英文标题】:How to set the progress tint color in UIProgressView 【发布时间】:2015-01-07 08:30:58 【问题描述】:

我想知道如何设置 UIProgressView 色调颜色。有时,根据颜色,默认高度不允许正确查看进度。如何解决这个问题?

【问题讨论】:

这里有两个不错的答案,是足以解决您的问题还是更清楚您的要求,以便其他人可以帮助您。 【参考方案1】:

你可以通过这个设置轨迹和进度条的色调;

对于轨道颜色:

progress.trackTintColor = [UIColor whiteColor]; 

进度条:

progress.progressTintColor = [UIColor redColor];

希望这会有所帮助.. :)

【讨论】:

【参考方案2】:

在 Swift 中,你可以这样做:

progressView.progressTintColor = UIColor.yellowColor()

【讨论】:

【参考方案3】:

斯威夫特 5:

progressBar.tintColor = UIColor(red: 33/255.0, green: 150/255.0, blue: 243/255.0, alpha: 1)
progressBar.tintColor = .blue

【讨论】:

使用 .tintColor 而不是 .progressTintColor 回避了我遇到的一个奇怪的滚动/单元格重用问题。谢谢。 .progressTintColor 对我不起作用 .tintColor 起作用【参考方案4】:

这对我来说是最好的方法:

[进度setProgressTintColor:UIColorFromRGB(0xaa0000)];

UIColorFromRGB 是:

#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue :((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

(可选):有时,根据颜色,进度没有得到正确的评价,需要增加进度条高度:

[进度setTransform:CGAffineTransformMakeScale(1.0, 3.0)];

【讨论】:

我遇到了缩放问题。即使我在更改颜色之前或之后添加你的变换线,滑块仍然会奇怪地缩放

以上是关于如何在 UIProgressView 中设置进度色调颜色的主要内容,如果未能解决你的问题,请参考以下文章