UITableViewCell Selected Background Color on Multiple Selection

后端 未结 14 968
夕颜
夕颜 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 05:04

    UITableViewCell has an attribute multipleSelectionBackgroundView. https://developer.apple.com/documentation/uikit/uitableviewcell/1623226-selectedbackgroundview

    Just create an UIView define the .backgroundColor of your choice and assign it to your cells .multipleSelectionBackgroundView attribute.

    0 讨论(0)
  • 2020-12-08 05:05

    This worked for me:

    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        var selectedCell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
        selectedCell.contentView.backgroundColor = UIColor.redColor()
    }
    
    // if tableView is set in attribute inspector with selection to multiple Selection it should work.
    
    // Just set it back in deselect 
    
    override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
        var cellToDeSelect:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath)!
        cellToDeSelect.contentView.backgroundColor = colorForCellUnselected
    }
    
    
    //colorForCellUnselected is just a var in my class
    
    0 讨论(0)
提交回复
热议问题