【发布时间】:2020-08-12 05:40:47
【问题描述】:
我的UITableView 需要一个标题。部分标题对我不起作用,因为它不应该与单元格一起滚动。
所以我像这样添加了tableView.tableHeaderView:
// ViewController
tableView.tableFooterView = UIView()
let header = SearchPopularHeaderView()
header.height(36)
tableView.tableHeaderView = header
// ...
// SearchPopularHeaderView
class SearchPopularHeaderView: UIView {
private var lblTitle: UILabel!
override init(frame: CGRect) {
super.init(frame: frame)
viewDidLoad()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
viewDidLoad()
}
private func viewDidLoad() {
lblTitle = UILabel()
lblTitle.text = "Most popular".localized()
lblTitle.font = UIFont.systemFont(ofSize: 12, weight: .bold)
lblTitle.textColor = UIColor("#e6f2f9")
self.addSubview(lblTitle)
lblTitle.centerY(to: self)
lblTitle.leadingToSuperview(offset: 16)
self.backgroundColor = UIColor("#3c4958")
layoutIfNeeded()
}
}
我试过了,还是不行:
为标签添加一个新的容器视图,将其边缘到超级视图,并更改此容器视图的颜色。看起来UIView 从UITableView 继承颜色。
问题:也许有人遇到了一些问题并且知道如何改变tableHeaderView的颜色?
附:请与tableHeaderView 相关的答案,我知道选项使它像一个节标题或只是一个单元格。谢谢。
【问题讨论】:
标签: ios swift uitableview uiview