views:

57

answers:

2

I am searching this for some time but I never found a solution.

I have a UITableView with custom cells, those cells have an image and I place the labels on it.

The thing is, when I select a cell, the whole cell frame is selected using the default highlight color. I tried changing the style, but if I use cell.selectionStyle = UITableViewCellSelectionStyleNone; the image won't highlight...

Just in case someone asks I created distincts images for highlighted / normal states.

+1  A: 

There is a property named highlighted in UITableViewCell.

@property(nonatomic, getter=isHighlighted) BOOL highlighted

So, you can modify the highlighted behavior by overwriting this method.

- (void)setHighlighted:(BOOL)value
{
   [super setHighlighted:value];

   // Do custom highlighted behavior here
   ...
}

Or overwrite setHighlighted:animated: method.


Something like this?

In MyCustomCell.m

- (void)setHighlighted:(BOOL)value
{
   [super setHighlighted:value];

   // Do custom highlighted behavior here
   if (value == YES)
   {
        // show highlighted image 
   } else {
        // show image for normal state. 
   }

   // propagate the highlighted message to other views.
   [mChildView setHighlighted:value];
}
Toro
Could you give me any code on how to do that? Put the image in highlighted state but don't highlight the cell
Lookez
A: 

I found a very good solution.

I didn't had to override any methods.

1 - In my CustomCell.xib I created 2 imageViews. One I connected to myImageView outlet, and the other to selectedBackgroundView.

2 - For the normal state I put myCustomBackgroundImg.png and in the Highlighted image I put a empty png, so it won't stay on top of the backgroundView when it's selected.

3 - And in the selectedBackgroundView I put myCustomSelectedBackgroundImg.png in the normal state image.

Hope this helps others.

Lookez