Use the following delegate method when your cell will become visible on the screen.
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
{
// call visible on the screen.
}
You can use delegate
methods of UITableviewCell
It is called when the cells became appears to the user.
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
//Set highlighted color here
}
It is called when the cells became disappears to the user.
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
//Set normal color here
}
Create a ViewController like this
class ViewController: UIViewController {
var color: UIColor = UIColor.red
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCell(withIdentifier: "Identifier") as! CustomCell
cell.labelToChange.textColor = color
return cell
}
}
On pen click change the color
to a different color and call tableView.reloadData()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.