[英]How to change color of the text in visible cell of tableview in ios swift
當您的單元格在屏幕上可見時,請使用以下委托方法。
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath)
{
// call visible on the screen.
}
您可以使用UITableviewCell的 delegate
方法
當單元格出現在用戶面前時被調用。
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
//Set highlighted color here
}
當單元格消失給用戶時調用。
func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
//Set normal color here
}
像這樣創建一個ViewController
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
}
}
在筆上單擊,將color
更改為其他顏色,然后調用tableView.reloadData()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.