【发布时间】:2014-06-28 19:51:49
【问题描述】:
我正在尝试将我的 UITableView 从全白更改为黑色背景,但是如何在 Interface Builder 中实现这一点?
【问题讨论】:
标签: ios uitableview ios7 xcode5
我正在尝试将我的 UITableView 从全白更改为黑色背景,但是如何在 Interface Builder 中实现这一点?
【问题讨论】:
标签: ios uitableview ios7 xcode5
根据苹果...
... 在 iOS 7 中,单元格默认为白色背景;在早期版本的 iOS 中,单元格继承了封闭表格视图的背景颜色。如果要更改单元格的背景颜色,请在表格视图委托的 tableView:willDisplayCell:forRowAtIndexPath: 方法中进行。
所以用代码来做,很简单...
首先,将其添加到 tableViewController 中的 viewDidLoad:
UIView *patternView = [[UIView alloc] initWithFrame:self.tableView.frame];
patternView.backgroundColor = [UIColor blackColor];
patternView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.backgroundView = patternView;
然后在你的 cellForRowAtIndexPath 中,添加这个:
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor whiteColor];
(textLabel 可以是你想要的任何颜色)
另请参考:UITableViewCell show white background and cannot be modified on iOS7
在 Interface Builder 中执行此操作时似乎存在错误。
【讨论】: