IOS: what is the default background color for a UITableViewCell

I want to set the background color for the labels inside the tableViewCell to be opaque, but I need the default background color for the uiTableViewCell that Apple provides.

So how can I get this background or what color?

Hello

+4
source share
4 answers

I found a solution: Different colors of the bg cell depending on the version of iOS (from 4.0 to 5.0)

To summarize, I just implement a method

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 

Thanks!

+1
source

You can register the background color of the cell

 NSLog(@"cell background color is %@", cell.backgroundColor); 

or cellView contents

 NSLog(@"cell contentView background color is %@", cell.contentView.backgroundColor); 

You can also just set the color of the shortcuts directly:

 label.backgroundColor = cell.contentView.backgroundColor; 
+1
source
 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; UIColor *color = [cell backgroundColor]; NSLog(@"%@",color); 

Result

2011-11-08 17: 09: 20.101 test1 [5439: 207] UIDeviceRGBColorSpace 1 1 1 1

Indicates that the default color is red = 1, green = 1, blue = 1, alpha = 1. This is white.

Note that the UITableViewCell also has a contentView property that contains the actual visible color.

+1
source

To reset the color of the redesigned (dequeued) UITableViewCell , this worked for me on iOS 5, 6, and 7:

 cell.backgroundColor = nil; 

As suggested here, I registered the value of this property for the newly created cell. I have seen null . This gave me the idea to lower the property. It seems to work in all three versions of iOS.

As I vaguely remember, iOS dramatically changed the default setting for colors in UITableView and UITableViewCell. In some versions, the colors of the parent containers were selected. In some versions, this default color was gray-white, but changed over time. IOS 7 White applies independently of parents. Note: do not quote me in this paragraph; See if you care. The fact is that the answers telling you to indicate a specific color give you bad advice.

+1
source

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


All Articles