-1

So I have a class:

class BoatTypeGame: UITableViewController

The table view has 14 rows. From rows 1-7, I want to make the color of the text green and for rows 8-14, I want to make the color of the text red. By the way, the cells will not have the same text every time the view loads; I used the arc4random_uniform() method to randomize the text. Thank you!

TheCentral
  • 35
  • 1
  • 6
  • You don't need to use attributed string in this case. Because you can change label color in `cellForRowAtIndexPath` or `tableViewWillDisplayCell` method – mustafa Dec 14 '14 at 17:47

1 Answers1

0

In your cellForRowAtIndexPath or even tableViewWillDisplayCell just use a switch statement or an if statement.

switch indexPath.row {
case 1...7:
    println("row 1-7")
    cell.textLabel?.textColor = UIColor.greenColor()
case 8...14:
    println("row 8-14")
    cell.textLabel?.textColor = UIColor.redColor()
default:
    break
}
Ian
  • 12,538
  • 5
  • 43
  • 62
  • Note: In swift you don't have to use `break` inside `case` statement that contains at least one expression. – mustafa Dec 14 '14 at 18:00