I have a custom grouped UITableViewCell, with a couple of UILabels on it. Since the UITableViewCell background color used to be pure white, it matched the UILabels\' default
You can call:
[[UIDevice currentDevice] systemVersion]
Although that is discouraged for a lot of reasons, and I'm not sure it's the best way to solve your problem. In principle, you should be able to deploy view code and get the consistent results you want by some other means.
If you do actually want to compare device versions, you'd probably set a property and check the device's OS when the view controller loads, as opposed to within your cellForRowAtIndexPath...
its use UIColor.systemBackground
but its available for IOS 13 Only
so use it likes this :
if #available(iOS 13.0, *) {
cell.backgroundColor = UIColor.systemBackground
} else {
cell.backgroundColor = .white
}
Nothing wrong with gcamp's answer, but if you'd prefer to keep the background white on both iOS4 and iOS5, then just do this:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setBackgroundColor:[UIColor whiteColor]];
}
I saw that problem in my custom UITableViewCell in a grouped TableView I just set the label background color to clear and that fixed it for me and works in iOS4 and iOS5. I set this in the custom cell code where the UILabel gets created as below:
[nameLabel setBackgroundColor:[UIColor clearColor]];
After that problem gone.
What I did was set the background color of the cell to [UIColor whiteColor] in willdisplaycell...
That way I control how things look.
In the delegate method tableView:willDisplayCell:
, the UITableViewCell
will have the background colour set to white or, in iOS 5, greyish.
You can change all your the backgroundColor
of all your subviews.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
for (UIView* view in cell.contentView.subviews) {
view.backgroundColor = cell.backgroundColor;
}
}