Reputation: 6402
I need to change the UITableView cell selection style from default blue to red. Can any one help me with this?
Upvotes: 4
Views: 8548
Reputation: 4162
You don't need an image or to subclass the cell. Simply do something like the following when creating the cell in your tableView:cellForRowAtIndexPath:
cell.selectedBackgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
cell.selectedBackgroundView.backgroundColor = [UIColor redColor];
Upvotes: 11
Reputation: 18368
If you sub-class UITableViewCell, you can modify its highlighted and selected UI behavior by overriding following methods.
- (void)setSelected:(BOOL)selected animated:(BOOL)animated;
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated;
For example:
- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
[super setHighlighted:highlighted animated:animated];
if (highlighted) {
self.backgroundColor = [UIColor redColor];
} else {
self.backgroundColor = [UIColor blackColor];
}
}
Upvotes: 3
Reputation: 1716
UIImageView *selectedBackground = [[UIImageView alloc] initWithFrame:self.view.frame];
selectedBackground.backgroundColor = [UIColor redColor];
[cell setSelectedBackgroundView:selectedBackground];
you can try something like this
Upvotes: 0