Return items in an array one by one until all items have been returned then start again
Hi,
What have is a UITable with a customCellwhich contains mutiple labes and what I want to do is be able to paint those labels with one of the four colors in an array. In other words I would like to paint the first row (cell) red, the second, blue, the third green, the fourth yellow and then start over again with the fifth one being red and so on.
The code I have blow keeps returning the first color only (red). Any idea how can I acoplish what I'm describing above?
- class CustomCell: UITableViewCell {
- @IBOutlet weak var labelPrice: UILabel!
- @IBOutlet weak var labelDiscount: UILabel!
- @IBOutlet weak var labelSavings: UILabel!
- @IBOutlet weak var labelTaxes: UILabel!
- let myColors = [colorMyRed, colorMyBlue, colorMyGreen, colorMyYellow]
- var nextItemIndex = 0// why this doesnt hold the value after being modified
- func myColor() -> UIColor {
- let result = myColors[nextItemIndex]
- nextItemIndex = nextItemIndex + 1
- return result
- }
- override func awakeFromNib() {
- super.awakeFromNib()
- let color:UIColor = myColor()
- labelPrice.textColor = color
- labelDiscount.textColor = color
- labelSavings.textColor = color
- labelTaxes.textColor = color
- }
- }