Custom UI TableViewCell selected backgroundcolor swift

前端 未结 11 950
盖世英雄少女心
盖世英雄少女心 2020-12-28 16:51

I am trying to change the appearance of a custom selected TableViewCell using Swift.

Do I need to do it via the designer or programmatically?

I tried the fol

11条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-28 17:08

    I have a likeness problem. In your cellForRowAtIndexPath method set:

    cell.selectionStyle = .None
    

    and then set didHighlightRowAtIndexPath...

    func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
        let cell  = tableView.cellForRow(at: indexPath)
        cell!.contentView.backgroundColor = .green
    }
    
    func tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) {
        let cell  = tableView.cellForRow(at: indexPath)
        cell!.contentView.backgroundColor = .clear
    }
    

提交回复
热议问题