有没有一种方法可以在不使用任何自定义View或xib的情况下更改Section Header和Footer背景颜色?
我不知道是否有Eureka特定/批准的方法,但是willDisplayHeaderView委托可以为我完成窍门:
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
if let header = view as? UITableViewHeaderFooterView {
header.backgroundView?.backgroundColor = UIColor.green
header.textLabel?.textColor = UIColor.yellow
}
}
适用于显示如下的标题:
var section = Section()
section.header = HeaderFooterView(stringLiteral: "Ugly Header")
form +++ section
FWIW,有一种使用onSetupView的Eureka方式,但是从3.1版开始,我认为它可能已损坏。
var hfv = HeaderFooterView(stringLiteral: "Ugly Header")
hfv.onSetupView = { view, _ in
if let header = view as? UITableViewHeaderFooterView {
header.backgroundView?.backgroundColor = .yellow
}
}
section.header = hfv
我不知道是否有Eureka特定/批准的方法,但是willDisplayHeaderView委托可以为我完成窍门:
func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { if let header = view as? UITableViewHeaderFooterView { header.backgroundView?.backgroundColor = UIColor.green header.textLabel?.textColor = UIColor.yellow } }
适用于显示如下的标题:
var section = Section() section.header = HeaderFooterView(stringLiteral: "Ugly Header") form +++ section
嗨@eliburke我尝试了这种方法,背景色不起作用,但是文本颜色起作用。 你能使它工作吗? 我正在使用Eureka 4.3.0
最有用的评论
我不知道是否有Eureka特定/批准的方法,但是willDisplayHeaderView委托可以为我完成窍门:
适用于显示如下的标题: