Changing the Background of a UITableViewCell

I know that it may have been set thousands of times, I tried to change the background for my UITablewViewCell with the following:

cell.contentView.backgroundColor = [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 now I have the following:

enter image description here

How to set the background color of the presentation of accessories?

UPDATE: I have a section title at the top in which it has a white background

+6
source share
3 answers

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]; } 
+13
source

You make it too complicated. You can simply change the background color of the table, which does exactly what you want. This way you do not need to set the color for the EVERY cell. :)

  self.tableView.backgroundColor = [UIColor greenColor]; 
0
source
 //in willDisplayCell if (indexPath.section > 0) { cell.backgroundColor = [UIColor blueColor]; } 
-3
source

Source: https://habr.com/ru/post/885872/


All Articles