简体   繁体   中英

How to change color of the text in visible cell of tableview in ios swift

On Pressing the pen button i can change the color of the theme as u can see.

在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

Now i want to change the text inside the visible cells to look like rest of the things color. How can i change the color of the text of a visible cell.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM