Change UITableView Cell Selection Style to Red
I need to change the UITableView cell selection style fr开发者_Go百科om default blue to red. Can any one help me with this?
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];
You could try setting the cells' selectedBackgroundView.image
, per this tutorial. That would give you the option of creating a nice gradient-based selection image, too.
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];
}
}
UIImageView *selectedBackground = [[UIImageView alloc] initWithFrame:self.view.frame];
selectedBackground.backgroundColor = [UIColor redColor];
[cell setSelectedBackgroundView:selectedBackground];
you can try something like this
精彩评论