如果你只是想设置相同的颜色到每一个分离器,它是不透明的,你可以使用:
self.tableView.separatorColor = UIColor.redColor()
如果您想要为分隔符使用不同的颜色或清除分隔符颜色或使用带有alpha的颜色。
小心:您必须知道在具有默认颜色的分隔符中存在backgroundView。
要改变它,你可以使用这个功能:
func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
if(view.isKindOfClass(UITableViewHeaderFooterView)){
var headerView = view as! UITableViewHeaderFooterView;
headerView.backgroundView?.backgroundColor = myColor
//Other colors you can change here
// headerView.backgroundColor = myColor
// headerView.contentView.backgroundColor = myColor
}
}
func tableView(tableView: UITableView, willDisplayFooterView view: UIView, forSection section: Int) {
if(view.isKindOfClass(UITableViewHeaderFooterView)){
var footerView = view as! UITableViewHeaderFooterView;
footerView.backgroundView?.backgroundColor = myColor
//Other colors you can change here
//footerView.backgroundColor = myColor
//footerView.contentView.backgroundColor = myColor
}
}
希望它能帮助!
添加变量并将其挂在IB中是我总是这样做的。 – s1mm0t 2010-07-29 16:52:49
那就是我在想什么。我正在做一个他们没有使用的教程和iVar,他们只是依靠委托和数据源回调。然而,他们从来没有访问分隔符颜色,所以也许这就是为什么 – fuzzygoat 2010-07-29 17:09:23