Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 649
PgmFreek Avatar asked Dec 02 '22 03:12

PgmFreek


2 Answers

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];
like image 198
ragamufin Avatar answered Dec 07 '22 01:12

ragamufin


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.

like image 34
Steve V. Avatar answered Dec 07 '22 01:12

Steve V.