disable the uitableview highlighting but allow the selection of individual cells

前端 未结 12 1237
心在旅途
心在旅途 2020-12-07 18:29

when you tap on a cell the row gets selected and highlighted.Now what i want to do is disable the highlighting but allow the selection.Is there a way around it.There is ques

相关标签:
12条回答
  • 2020-12-07 18:50

    You can set the selection property of the cell itself in the storyboard

    0 讨论(0)
  • 2020-12-07 18:55

    Change UITableViewCell's selectedBackgroundView color to transparent.

        let clearView = UIView()
        clearView.backgroundColor = UIColor.clearColor() // Whatever color you like
        UITableViewCell.appearance().selectedBackgroundView = clearView
    

    or to set for a specific cell:

    cell.backgroundView = clearView

    0 讨论(0)
  • 2020-12-07 18:58

    You can just set the cell's selection style to "None" from Storyboard:

    See here

    Or from code:

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    

    For Swift 3:

    cell.selectionStyle = UITableViewCellSelectionStyle.none
    

    For Swift 4 & above:

    cell.selectionStyle = .none
    
    0 讨论(0)
  • 2020-12-07 19:02

    For Swift 3.0:

    cell.selectionStyle = .none
    
    0 讨论(0)
  • 2020-12-07 19:03

    For Swift:

    UITableViewCell.selectionStyle = UITableViewCellSelectionStyle.None;

    Or when you subclass a cell in swift:

    class CustomCell : UITableViewCell {
    
        required init(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)!
            selectionStyle = .None
        }
    
    }
    
    0 讨论(0)
  • 2020-12-07 19:03

    For Swift 5 the best way is:

    cell.selectionStyle = .none
    
    0 讨论(0)
提交回复
热议问题