Cree un círculo con segmentos multicolores en Core Graphics

Estoy tratando de dibujar un gráfico circular que estará formado por segmentos de igual tamaño, cada uno con un color diferente. Estoy basando mi código en estoSO: Dibuje un progreso de segmento circular en SWIFT

let circlePath = UIBezierPath(ovalInRect: CGRect(x: 200, y: 200, width: 150, height: 150))
var segments: [CAShapeLayer] = []
let segmentAngle: CGFloat = 1.0 / CGFloat(totalSegments)

for var i = 0; i < totalSegments; i++ {
    let circleLayer = CAShapeLayer()
    circleLayer.path = circlePath.CGPath

    // start angle is number of segments * the segment angle
    circleLayer.strokeStart = segmentAngle * CGFloat(i)

    //create a gap to show segments
    let gapSize: CGFloat = 0.008
    circleLayer.strokeEnd = circleLayer.strokeStart + segmentAngle - gapSize

    circleLayer.lineWidth = 10
    circleLayer.strokeColor = UIColor(red:0,  green:0.004,  blue:0.549, alpha:1).CGColor
    circleLayer.fillColor = UIColor.redColor().CGColor

    // add the segment to the segments array and to the view
    segments.insert(circleLayer, atIndex: i)
    view.layer.addSublayer(segments[i])
}

Pero usando esto, quería hacerlo para poder colorear cada segmento en función del valor de índice i en el bucle for. Inicialmente, solo probé con pares o impares, pero descubrí que la parte de relleno llenaría todo el círculo con el último color utilizado.

Sospecho que se debe a que el color de relleno llena todo el círculo, a pesar de que el trazo tiene un comienzo y un fin finitos. ¿Cómo podría crear este mismo efecto pero habilitar un color de relleno separado para cada segmento?

Respuestas a la pregunta(1)

Su respuesta a la pregunta