0

I have a standard UITableViewCell on which I add a few extra views to in order to create a custom look. One of these such views is a UILabel that I've put a border and background color on, in order for it to look sort of like a separate bubble. When a user taps on the cell, I want it to still highlight, but only on where this UILabel is, not the entire cell (it looks ugly when it highlights the whole cell). How can I do this?

Anything with the selection style of the cell seems to only change the color or style, but I want to change the area of the cell that is highlighted.

Thanks in advance.

Rohan
  • 541
  • 1
  • 11
  • 24
  • possible duplicate of [Custom UITableViewCell selection style?](http://stackoverflow.com/questions/11920156/custom-uitableviewcell-selection-style) – rishi Jun 12 '14 at 04:17
  • @rishi That helps, but it seems like the only way is to subclass `UITableViewCell`. Is that the only way? – Rohan Jun 12 '14 at 04:22
  • Please understand, what you get from the generic `UITableVIewCell` , is just that, a *generic* cell. Meaning, that ANY change you want that is NOT part of a generic cell, you should subclass. Let me add: Subclassing `UITableVIewCell` is something you should not be afraid of. It is a good thing to feel comfortable with and once done, it's easy to make other changes. – bauerMusic Jun 12 '14 at 04:33

1 Answers1

0

Another way to achieve it is,

  1. In CellForRowAtIndexPath, check whether the index path of the cell you are rendering is same as tableview.indexPathForSelectedRow. If same, give a highlighted look which you want.

  2. In didSelectRowAtIndexPath reload the previously selected cell and currently selected cell. [You have to cache the previous selected index to reset the highlighted look.]

nprd
  • 1,942
  • 1
  • 13
  • 16