UITableViewCell Selected Background Color on Multiple Selection

后端 未结 14 1015
夕颜
夕颜 2020-12-08 04:26
// Doesn\'t work
cell.selectionStyle = .Blue
//Works when the selection is not multiple, if it\'s multiple with each selection the previous one disappear...
let cell         


        
14条回答
  •  感情败类
    2020-12-08 04:42

    SWIFT 3/4

    Solution for CustomCell.selectionStyle = .none if you set some else style you saw "mixed" background color with gray or blue.

    And don't forget! func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) didn't call when CustomCell.selectionStyle = .none.

    extension MenuView: UITableViewDelegate {
        func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
            let cellType = menuItems[indexPath.row]
            let selectedCell = tableView.cellForRow(at: indexPath)!
                selectedCell.contentView.backgroundColor = cellType == .none ? .clear : AppDelegate.statusbar?.backgroundColor?.withAlphaComponent(0.15)
    
            menuItemDidTap?(menuItems[indexPath.row])
    
            UIView.animate(withDuration: 0.15) {
                selectedCell.contentView.backgroundColor = .clear
            }
        }
    }
    

提交回复
热议问题