views:

774

answers:

2

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

+4  A: 

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
Can you elaborate on the first method? I tried `cell.selectedBackgroundView.backgroundColor = [UIColor redColor]` but it didn't seem to change anything.
Daniel Dickison
I updated my answer.
Can Berk Güder
A: 

i clean up a demo refer to http://code.google.com/p/table-group-cell-background-color-demo/, may be you could have a look at it and get some help

jiansihun