Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: What is the default background color of UITableViewCell

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

So how can I get this background or what color is it?

Regards

like image 379
Borut Tomazin Avatar asked Nov 08 '11 13:11

Borut Tomazin


2 Answers

To reset the color of a recycled (dequeued) UITableViewCell, this has worked for me in iOS 5, 6, and 7:

cell.backgroundColor = nil;

As others suggested here, I logged the value of that property for a newly created cell. I saw null. That gave me the idea to nil out the property. Seems to be working in all 3 iOS versions.

As I vaguely recall, iOS has changed drastically the way defaults are set for colors in UITableView and UITableViewCell. In some versions parent containers colors were picked up. In some versions, that default color was greyish white, but changed over time. In iOS 7 White is applied regardless of parents. Note: Don't quote me on this paragraph; look it up if you care. The point is that answers telling you to set a specific color are giving you bad advice.

like image 164
Basil Bourque Avatar answered Sep 30 '22 17:09

Basil Bourque


You can log the background color of the cell

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

or the cell's contentView

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

You could also just set your label's color directly:

label.backgroundColor = cell.contentView.backgroundColor;
like image 21
jbat100 Avatar answered Sep 30 '22 18:09

jbat100