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
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
I have found a solution: Different cell bg color depending on iOS version (4.0 to 5.0)
To sum up I just implement method
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
Thanks!
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;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIColor *color = [cell backgroundColor];
NSLog(@"%@",color);
Result is
2011-11-08 17:09:20.101 test1[5439:207] UIDeviceRGBColorSpace 1 1 1 1
It indicates that default color is Red=1, Green=1, Blue=1, alpha=1. It's a white color.
Note, that UITableViewCell also has contentView
property, which contains real visible color.
I have found a solution: Different cell bg color depending on iOS version (4.0 to 5.0)
To sum up I just implement method
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
Thanks!
© 2022 - 2024 — McMap. All rights reserved.