Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 环形压缩径向梯度_Ios_Swift_Uicolor - Fatal编程技术网

Ios 环形压缩径向梯度

Ios 环形压缩径向梯度,ios,swift,uicolor,Ios,Swift,Uicolor,我在我的swift 4项目中使用[UICircularProgressing]库来显示进度循环条。我使用的类型是gradient,它不是一个完整的圆。开始角度为120,结束角度为60。我面临着渐变颜色的问题。它不适用于径向。我想要一个渐变,从绿色开始,然后是黄色,最后是红色。与此图片相同,第一个和最后一个颜色颠倒 这就是我实际拥有的: 使用此代码: func configureRing() { ringView.delegate = self let gree

我在我的
swift 4
项目中使用[UICircularProgressing]库来显示
进度循环条
。我使用的类型是
gradient
,它不是一个完整的圆。
开始角度
为120,
结束角度
为60。我面临着
渐变
颜色的问题。它不适用于径向。我想要一个渐变,从绿色开始,然后是黄色,最后是红色。与此图片相同,第一个和最后一个颜色颠倒

这就是我实际拥有的:

使用此代码:

func configureRing() {
        ringView.delegate = self
        let green = UIColor(hexString: "#31c8b4")!
        let yellow = UIColor(hexString: "#fbd16a")!
        let red = UIColor(hexString: "#fe160f")!
        ringView.ringStyle = .gradient

        ringView.gradientColors = [green, red]
        ringView.gradientColors = [green, yellow, red]
        ringView.gradientColorLocations = [0, 0.5, 1]
        ringView.gradientStartPosition = UICircularProgressRingGradientPosition.bottomLeft
        ringView.gradientEndPosition = UICircularProgressRingGradientPosition.bottomRight
        ringView.value = 100
    }
如你所见,黄色部分非常小

[UICircularProgressing]=

编辑: 当我添加更多颜色时,我得到的是:

ringView.gradientColors = [green, yellow, yellow, red]
ringView.gradientColorLocations = [0, 0.4, 0.6, 1]

我对UICircularProgressing一无所知,但我知道如何指定渐变。因此,假设这是一种正常的工作方式,您可以尝试以下方法:

    ringView.gradientColors = [green, yellow, yellow, red]
    ringView.gradientColorLocations = [0, 0.4, 0.6, 1]
当然,根据需要调整颜色和位置。当我用普通的CAGradientLayer做这类事情时,我会得到:


。。。这似乎是沿着渐变分布颜色,而不是像你所描述的那样。

@matt我希望每种颜色都能得到Arcook的1/3,所以添加更多的颜色和位置来指定。你现在所说的是“在中间点短暂通过黄色”。所以计算机正在这样做。它只会照你说的做。如果你想要更多,告诉它更多。@matt请参阅我的编辑please@NeAS你解决这个问题了吗?我有同样的问题,我提供了4种颜色的圆圈(每种颜色1/4),但它重复了HI@NeAS。我设置渐变颜色有困难。你能在这里回答我你的密码吗?