ios - TableView 页脚位置不正确
问题描述
我的第一次尝试将页脚放置在正确的位置,但是它太靠近前导边距,这使我添加了 1 个约束来解决问题。这样做会导致页脚高于页眉,这显然不是预期的行为。我想做的就是从我的第一次尝试中增加 10 分的领先优势。想法?
第一次尝试:
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
if section == 0 {
let label = UILabel()
label.text = "Your birth month is not set"
label.font = UIFont.preferredFont(forTextStyle: .footnote)
label.textColor = UIColor.gray
return label
}
return UIView()
}
第二次尝试:
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
if section == 0 {
let label = UILabel()
view.addSubview(label)
label.translatesAutoresizingMaskIntoConstraints = false
let constraints = label.leadingAnchor.constraint(equalTo: view.layoutMarginsGuide.leadingAnchor, constant: 10)
NSLayoutConstraint.activate([constraints])
label.text = "Your birth month is not set"
label.font = UIFont.preferredFont(forTextStyle: .footnote)
label.textColor = UIColor.gray
return label
}
return UIView()
}
解决方案
尝试放置此代码。根据您的要求进行框架更换。
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let headerView = UIView(CGRect(x: 0, y: 0, width: tableView.frame.width, height: 50))
let lblDate = UILabel(frame: CGRect(x: 10, y: 0, width: headerView.frame.width - 10, height: 50))
headerView.addSubview(lblDate)
lblDate.text = "text"
return headerView
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 50
}
推荐阅读
- r - 如何在 R 中使用“group_by”和“mutate”而不创建一长串属性?
- c - 基于函数原型的调用参数编译时决策
- firebase - 没有密码创建的 Firebase 用户仍然可以登录吗?
- android - AndroidResultContracts.TakePicture() 返回布尔值而不是位图
- perl - 在 MacOS catalina 中安装 Tk 模块 perl 时出现问题
- reactjs - react-multiselect-checkboxes - 如何隐藏搜索框
- qt - Qt Quick QML 窗口中的多种模式?
- r - 如何提取用户在闪亮的应用程序中选择的滑块的值,以便在函数中使用它?
- powershell - PSCustomObject out-gridview 格式不正确
- ios - 在允许 FCM 推送通知时修复错误 403