I know about UITableview: How to Disable Selection for Some Rows but Not Others and cell.selectionStyle = UITableViewCellSelectionStyleNone
, but how do I make a cell (or any UIView
for that matter) appear disabled (grayed-out) like below?
You need to set the selectionStyle property on the cell: cell. selectionStyle = UITableViewCellSelectionStyle. None in Swift, or cell.
You can just disable the cell's text fields to gray them out:
Swift 4.x
cell!.isUserInteractionEnabled = false cell!.textLabel!.isEnabled = false cell!.detailTextLabel!.isEnabled = false
A Swift extension that works well in the context I'm using it; your mileage may vary.
Swift 2.x
extension UITableViewCell { func enable(on: Bool) { for view in contentView.subviews as! [UIView] { view.userInteractionEnabled = on view.alpha = on ? 1 : 0.5 } } }
Swift 3:
extension UITableViewCell { func enable(on: Bool) { for view in contentView.subviews { view.isUserInteractionEnabled = on view.alpha = on ? 1 : 0.5 } } }
Now it's just a matter of calling myCell.enable(truthValue)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With