我正在做一个项目。我有很多设置为清晰颜色的 UITableView
。他们 View 的背景颜色设置为我的自定义颜色,并且在 iPhone 上一切正常。
问题出现在 iPad 上!我几乎尝试了所有方法,但我的 UITableView
是白色的。
我查看了其他主题,例如: UITableView backgroundColor always gray on iPad ,但没有任何效果。还有,我的问题不是灰色,而是雪白的!
这可能是什么原因?
最佳答案
好消息:根据发行说明,对于 iOS 10:
When running on iPad, the background color set for a UITableViewCell in a Storyboard is now respected.
对于版本
我在 iOS 8 (8.3) 中看到了这一点。即使在 IB 中我的单元格是“清晰的颜色”并且它们的内容 View 是“清晰的颜色”,它们也会呈现为白色。一个不完美但合理的解决方案,因为它仍然从 IB 获取值:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
cell.backgroundColor = cell.contentView.backgroundColor;
return cell;
}
在 iPad 上,我的出列可重复使用单元格的背景似乎被强制为白色。我能够使用 View 层次结构调试器确定这一点。
一旦我这样做了,我就可以使用表格的背景颜色,而不必设置背景 View ,尽管这样也可以。
https://stackoverflow.com/questions/27551291/