2

I'm using grouped style UITableView, with multiple rows in sections, now i want to customize row select style. Can we do that without subclassing UITableViewCell ? Thanks!

Blios
  • 719
  • 1
  • 16
  • 30

2 Answers2

4

UITableViewCell has a property for the backgroundView as well as the selectedBackgroundView.

When the cell gets selected it will automatically switch from showing the backgroundView to instead show the selectedBackgroundView.

So create a new UIView and give it a green background color (the size of the view doesn't matter as the cell will resize the view to cover the entire background). Then set that green view as the selectedBackgroundView of your cell. Now then the cell gets selected your green view will show.

If you want to have a gradient for your selection then you would draw a gradient in your selection view and make sure it's stretches correctly.

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
1

Use one of this:

cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.selectionStyle = UITableViewCellSelectionStyleBlue;
edzio27
  • 4,126
  • 7
  • 33
  • 48