Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7530249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:51:36+00:00 2026-05-30T04:51:36+00:00

I have looked around to find a solution for setting the background color of

  • 0

I have looked around to find a solution for setting the background color of the accessoryView to the same background color as the cell´s contentView.

    cell.contentView.backgroundColor = [UIColor colorWithRed:178/255.f green:14/255.f blue:12/255.f alpha:0.05];
    cell.accessoryView.backgroundColor =[UIColor colorWithRed:178/255.f green:14/255.f blue:12/255.f alpha:0.05];

There is a solution that works but only let me use one color for all cells.

cell.contentView.superView.backgroundColor = [UIColor redColor];

Is the only solution to not use the accessoryView and use an image instead?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T04:51:37+00:00Added an answer on May 30, 2026 at 4:51 am

    I struggled with this one for a little while too and resorted to creating a custom image with the accessory. But I just found this solution that works well and doesn’t require a custom image. The trick is to change the cell’s backgroundView color not the backgroundColor.

    UIView *myView = [[UIView alloc] init];
    if (indexPath.row % 2) {
        myView.backgroundColor = [UIColor whiteColor];
    } else {
        myView.backgroundColor = [UIColor blackColor];
    }
    cell.backgroundView = myView;
    

    No need to change the accessoryView or contentView background colors. They’ll follow automatically.


    Note for 2014. Very typically you wold use -(void)setSelected:(BOOL)selected animated:(BOOL)animated

    So, you’d have a custom cell class, and you’d set the colours for the normal/selected like this…

    HappyCell.h
    @interface HappyCell : UITableViewCell
    @property (strong, nonatomic) IBOutlet UILabel *mainLabel;
    etc...
    @end
    
    HappyCell.m
    @implementation HappyCell
    
    -(id)initWithStyle:(UITableViewCellStyle)style
          reuseIdentifier:(NSString *)reuseIdentifier
        {
        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
        if (self)
            {
            }
        return self;
        }
    
    -(void)awakeFromNib
        {
        }
    
    - (void)setSelected:(BOOL)selected animated:(BOOL)animated
        {
        [super setSelected:selected animated:animated];
    
        if(selected)
            {
            self.backgroundColor = [UIColor redColor];
            .. other setup for selected cell
            }
        else
            {
            self.backgroundColor = [UIColor yellowColor];
            .. other setup for normal unselected cell
            }
        }
    
    @end
    
    // to help beginners.......
    // in your table view class, you'd be doing this...
    
    -(NSInteger)tableView:(UITableView *)tableView
          numberOfRowsInSection:(NSInteger)section
        {
        return yourDataArray.count;
        }
    
    -(UITableViewCell *)tableView:(UITableView *)tv
          cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
        NSInteger thisRow = indexPath.row;
        ContentsCell *cell = [tv
          dequeueReusableCellWithIdentifier:@"cellName"
          forIndexPath:indexPath]; 
        // "cellName" must be typed in on the cell, the storyboard
        // it's the "identifier", NOT NOT NOT the restorationID
    
        [cell setupForNumber: thisRow];
        cell.mainLabel.text = yourDataArray[ thisRow ][@"whatever"];
        cell.otherLabel.text = yourDataArray[ thisRow ][@"whatever"];
    
        return cell;
        }
    

    hope it helps someone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have looked around and have yet to find a solution to this problem.
Looked around SO but couldn't find anything useful, so.. I have a Backbone.js contacts
I have looked around the internet for 3 hours now looking for a solution
I looked around on Stack Overflow and I didn't find the solution of a
I've looked around a bit and can't find a solution that solves my problem.
I've looked around and can't seem to quite find a solution that meets my
I've looked around, and I'm trying to find an elegant solution to this, and
I have looked around and still can't find how to list all my tables
I have looked around the net and cannot find a project for this game.
I have looked around the internet but haven't been able to find a working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.