开发者

changing UITableViewCell background

开发者 https://www.devze.com 2023-02-24 06:28 出处:网络
I know this might have been asked thousands time, I tried changing the background for my UITablewViewCell via the following:

I know this might have been asked thousands time, I tried changing the background for my UITablewViewCell via the following:

 cell.contentView.backgroundColo开发者_开发技巧r = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1];
              cell.textLabel.backgroundColor = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1];

and all I have now is:

changing UITableViewCell background

How do I set that accessory view background view color as well?

UPDATE: I have a section header on top in which it has a white background


Put this in your UITableViewDelegate:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.backgroundColor = [UIColor colorWithRed:0 green:0.188235 blue:0.313725 alpha:1];
}


You're over-complicating it a bit. You can just change the tableview's background color which does exactly what you want. This way, you don't have to set the color for EVERY cell. :)

    self.tableView.backgroundColor = [UIColor greenColor];


//in willDisplayCell
if (indexPath.section > 0) {
    cell.backgroundColor = [UIColor blueColor];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消