[英]UITableView - footer for section - iPhoneX
I have problem with iPhone and UITableView
section footer. 我在iPhone和UITableView
节的页脚有问题。 It is being "hidden" behind the top cut-out section. 它被“隐藏”在顶部切除部分的后面。
I have this code: 我有以下代码:
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
}
My UITableViewController
is added from storyboard and safe areas are set. 我的UITableViewController
是从情节UITableViewController
中添加的,并设置了安全区域。 I have no problem with table lines, only with section footer. 我对表格行没有任何问题,仅对页脚有问题。
It seems that I have solved the problem with this code, added after footerView.addSubview(explanationLabel)
: 看来我已经用在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.