I have a method that returns a new color each time it is called and what I want to do is be able to color the rows with a new color each time a new one is added.
With the code below I only get red
rows, the blue, green and yellow are never called.
Again, what I need to do is be able to color each row with one of the four colors in the array, the first row red
the second blue
, the third one green
the fourth one yellow
and then start coloring the fifth one red
again, the sixth blue
and so on.
class CustomCell: UITableViewCell {
let myColors = [colorMyRed, colorMyBlue, colorMyGreen, colorMyYellow]
var nextItemIndex = 0
func color() -> UIColor {
let result = myColors[nextItemIndex]
nextItemIndex = nextItemIndex + 1
return result
}
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
// how can I assign a new color to this variable
// each time awakeFromNib is called
let myColor:UIColor = color()
// these labels need to be colored with one of the
// four colors each time a new row is added
labelPrice.textColor = myColor
labelDiscount.textColor = myColor
labelSavings.textColor = myColor
}
}
Any suggestion?