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
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With