How do I change the selection color in Uitableview?

How do I change the selection color in Uitableview?

you can just change the backgroundView’s backgroundColor property like so: cell. selectedBackgroundView?. backgroundColor = Swift 4+:

  1. Add a view to the content view of your cell.
  2. Right click your cell.
  3. Make the added view as “selectedBackgroundView”.

How do you change the color of the selected cell in Swift?

“change selection color uitableviewcell swift” Code Answer

  1. override func setSelected(_ selected: Bool, animated: Bool) {
  2. super. setSelected(selected, animated: animated)
  3. if selected {
  4. contentView. backgroundColor = UIColor. green.
  5. } else {
  6. contentView. backgroundColor = UIColor. blue.
  7. }

How do I change the color of a table view?

Change the background color of Table View Cell. In the Document Outliner, select the Table View’s cell. Click on the Attributes inspector. In the View section set the background color to red: 108, green: 255, blue: 146, alpha 1.

How to remove tableview selection color in swift?

Inside the cellForRowAt indexPath method, on the table view cell, set the selectionStyle to . none .

How to deselect a cell in uitableviewcell?

I have a subclassed UITableViewCell. All you have to do is set the background color in the touch events, which simulates selection on touch, and then set the background color in the setSelected function. Setting the background color in the selSelected function allows for deselecting the cell.

What is the default value for selectedbackgroundview cells?

I think you were on the right track, but according to the class definition for selectedBackgroundView: The default is nil for cells in plain-style tables (UITableViewStylePlain) and non-nil for section-group tables UITableViewStyleGrouped).

How do I set the background color of selected cells?

All you have to do is set the background color in the touch events, which simulates selection on touch, and then set the background color in the setSelected function. Setting the background color in the selSelected function allows for deselecting the cell.

How does the UIAlertView work?

The code is very easy to understand. When a row is selected, the app creates an UIAlertView and shows an alert message. Try to run the app and this is what the app looks like when you tap a row: For now, we just display a generic message when a row is selected.