1

I doing a project where i need to use highlighted table view color not default.

Rana
  • 247
  • 8
  • 18

2 Answers2

9

Of course you can.

There are two methods to achieve this:

  1. Use UITableViewCell's selectedBackgroundView and selectedTextColor properties
  2. Subclass UITableViewCell and implement the drawInRect and setSelected:animated: methods

The latter option gives you more flexibility and much better performance, but it might be slightly harder if you haven't used CoreGraphics before.

UPDATE In response to the OP's comment:

Here's how you can use the selectedBackgroundView property:

UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 60)];
[bgView setBackgroundColor:[UIColor redColor]];
[cell setSelectedBackgroundView:bgView];
[bgView release];

I haven't tried this myself, but it should work.

Can Berk Güder
  • 109,922
  • 25
  • 130
  • 137
  • Can you elaborate on the first method? I tried `cell.selectedBackgroundView.backgroundColor = [UIColor redColor]` but it didn't seem to change anything. – Daniel Dickison Apr 09 '09 at 17:49
1

Try referring to this demo - maybe you could have a look at it and get some help.

Mxyk
  • 10,678
  • 16
  • 57
  • 76
jiansihun
  • 11
  • 1
  • 4