【发布时间】:2015-11-10 02:44:30
【问题描述】:
我正在尝试创建一个包含 UITableView 的简单视图。 我想通过表视图的 backgroundColor 属性将表视图的背景颜色更改为紫色。 Apple 文档说您只需将 backgroundView 属性设置为 nil 即可工作。就我而言,它不起作用。
我必须调用 UITableView.appearance().backgroundColor = UIColor.purpleColor() 让它工作而不仅仅是 UITableView.backgroundColor = UIColor.purleColor()
我的问题是为什么?
这是代码:
class TaskTableView: UIView {
var tableView = UITableView(frame: CGRectZero, style: .Plain)
override init(frame: CGRect) {
super.init(frame: frame)
tableView.backgroundView = nil
tableView.backgroundColor = UIColor.purpleColor()
tableView.separatorStyle = UITableViewCellSeparatorStyle.None
tableView.translatesAutoresizingMaskIntoConstraints = false
addSubview(tableView)
let views = ["table": tableView]
addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat("|[table]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
)
addConstraints(
NSLayoutConstraint.constraintsWithVisualFormat("V:|[table]|", options: NSLayoutFormatOptions(rawValue: 0), metrics: nil, views: views)
)
}
required init?(coder aDecoder: NSCoder) {
fatalError()
}
}
【问题讨论】:
标签: ios uitableview cocoa-touch