Search code examples
iosswiftuitableviewtextcolor

Change text color in tableview cell in didHighlightRowAt


I have this code:

func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
        let cell  = tableView.cellForRow(at: indexPath)
        cell!.contentView.backgroundColor = .blue
        cell?.textLabel?.textColor = UIColor.white
        var cell2 = tableView.cellForRow(at: indexPath) as! DataTableViewCell
       cell2.textLabel.textColor = UIColor.white
    }

The background change works fine, but the text color change does not work.

Does anyone know why and how to fix this problem?


Solution

  • cell.textLabel.highlightedTextColor = [UIColor greencolor];