PgmFreek
PgmFreek

Reputation: 6402

Change UITableView Cell Selection Style to Red

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

Answers (4)

ragamufin
ragamufin

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

AechoLiu
AechoLiu

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

Kshitiz Ghimire
Kshitiz Ghimire

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

Steve V.
Steve V.

Reputation: 153

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.

Upvotes: 5

Related Questions