ios - UIBezierPath 为每个部分放置一种颜色,导致最后一个颜色

标签 ios swift uibezierpath

我想为每件作品添加一种颜色。我补充道:

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

我忘记打电话了 索引++

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

/Main.storyboard:错误:IB Designables:无法渲染 WaitingCircleView 的实例:渲染 View 花费的时间超过 200 毫秒。您的绘图代码可能会受到性能缓慢的影响。

最佳答案

你可能打算

var index = 0 

并且,在循环内:

index++

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

相关文章:

iOS:如果屏幕被锁定,访问前置摄像头

ios - Swift 使用 NSFetchedResultsController 更新 TableView

ios - 我可以合并多个透明 SCNShape 对象吗?

ios - 如何计算弯曲的 SKSpriteNode 的 "center"点?

objective-c - 有没有办法忽略 objective-c 中的 uitouch?

ios - 将图像添加到 MKAnnotationView 会取代 pin

ios - 在多个类中调用闭包?

ios - UITabbarController 设置初始 View

ios - 添加 appledoc 时出错

swift - 尝试使用 Swift 3 构建指向城市的指南针