iphone – how to set custom color of table row – Education Career Blog

how to set custom color of table row when it is clicked…

i mean i don’t want that blue color which appear by Default….


To get whatever color you want, you have to replace the selectedBackgroundView with your own UIView.

- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"CellID";
    UITableViewCell *cell = table dequeueReusableCellWithIdentifier:CellIdentifier;
    if (!cell) {
        cell = UITableViewCell alloc initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier autorelease;
        UIView *selectedBackground = UIView alloc init autorelease;
        selectedBackground.backgroundColor = UIColor magentaColor;
        cell.selectedBackgroundView = selectedBackground;
    // configure cell
    return cell;


you can set the tableView cell property

cell.selectionStyle = UITableViewCellSelectionStyleGray; 


Make your own subclass of UITableViewCell. Overwrite the method -(void)setSelected:(BOOL)selected

Something like this:

- (void)setSelected:(BOOL)selected {
       super setSelected:selected;
       if (selected) {
             self.backgroundColor = UIColor greenColor;
       } else {
             self.backgroundColor = UIColor whiteColor;

Leave a Comment