[英]UITableView - footer for section - iPhoneX
我在iPhone和UITableView
節的頁腳有問題。 它被“隱藏”在頂部切除部分的后面。
我有以下代碼:
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
var content = "some long text"
let footerView = UIView(frame: CGRect(x: 0, y: 0, width: view.frame.size.width, height: 40))
let explanationLabel = UILabel(frame: CGRect(x: 10, y: 0, width: view.frame.size.width - 20, height: 50))
explanationLabel.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.light)
explanationLabel.textColor = UIColor.darkGray
explanationLabel.numberOfLines = 0
explanationLabel.lineBreakMode = .byTruncatingTail
explanationLabel.text = content
footerView.addSubview(explanationLabel)
return footerView
}
我的UITableViewController
是從情節UITableViewController
中添加的,並設置了安全區域。 我對表格行沒有任何問題,僅對頁腳有問題。
看來我已經用在footerView.addSubview(explanationLabel)
之后添加的代碼解決了這個問題:
explanationLabel.translatesAutoresizingMaskIntoConstraints = false
if #available(iOS 11.0, *) {
let guide = footerView.safeAreaLayoutGuide
NSLayoutConstraint.activate([
explanationLabel.topAnchor.constraint(equalTo: footerView.topAnchor),
explanationLabel.leadingAnchor.constraint(equalTo: guide.leadingAnchor, constant: 10),
explanationLabel.trailingAnchor.constraint(equalTo: guide.trailingAnchor, constant: -10),
explanationLabel.bottomAnchor.constraint(equalTo: footerView.bottomAnchor)
])
}
else {
NSLayoutConstraint.activate([
explanationLabel.topAnchor.constraint(equalTo: footerView.topAnchor),
explanationLabel.leadingAnchor.constraint(equalTo: footerView.leadingAnchor, constant: 10),
explanationLabel.trailingAnchor.constraint(equalTo: footerView.trailingAnchor, constant: -10),
explanationLabel.bottomAnchor.constraint(equalTo: footerView.bottomAnchor)
])
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.