我想为每块涂一种颜色。我补充说:

let colors = [
    [54.0/255.0, 78.0/255.0 ,44.0/255.0 ],
    [252.0/255.0, 178.0/255.0, 141.0/255.0 ],
    [242.0/255.0, 44.0/255.0 ,173.0/255.0 ],
    [239.0/255.0, 42.0/255.0 , 93.0/255.0 ],
    [169.0/255.0, 145.0/255.0, 135.0/255.0],
    [122.0/255.0, 228.0/255.0, 140.0/255.0],
    [110.0/255.0, 134.0/255.0, 36.0/255.0,],
    [32.0/255.0, 143.0/255.0, 55.0/255.0,],
    [178.0/255.0, 78.0/255.0, 6.0/255.0,],
    [39.0/255.0, 53.0/255.0, 27.0/255.0,],
    [46.0/255.0, 122.0/255.0, 151.0/255.0,],
]


let points = [[270, 290],[300, 320],[330, 350],[0, 20],[30, 50],[60, 80],[90, 110],[120, 140],[150, 170],[180, 200],[210, 230],[240, 260]]
func drawSmallCircles(){
    let index = 0
    for oneArray in points {
        let startAngleRadiant: CGFloat = degreesToRadians(Double(oneArray[0]))
        let endAngleRadiant: CGFloat = degreesToRadians(Double(oneArray[1]))
        let radius: CGFloat = 50.0
        let path = UIBezierPath(arcCenter: CGPoint(x: CGFloat(100), y: CGFloat(100)),
            radius: radius,
            startAngle: startAngleRadiant,
            endAngle: endAngleRadiant,
            clockwise: true)
        let color = UIColor(red: CGFloat(colors[index][0]), green: CGFloat(colors[index][1]), blue: CGFloat(colors[index][2]), alpha: CGFloat(1))
        color.setStroke()
        path.lineWidth = CGFloat(10)
        path.stroke()
    }
}

override func drawRect(rect: CGRect) {
    self.opaque = false;
    drawSmallCircles()
}

但总是显示最后一种颜色。

更新1

我忘了打电话
索引++

但是当我这样做时,我得到了htis错误:

/Main.storyboard:错误:IB Designables:无法渲染WaitingCircleView实例:渲染视图花费的时间超过200毫秒。您的绘图代码可能会降低性能。

最佳答案

你可能打算

var index = 0

并且,在循环内:
index++

关于ios - UIBezierPath为每块放置一种颜色,导致最后一种颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33770195/

10-11 19:48