我试图让用户插入他们的个人资料,我做到了。但我遇到了一个问题。
页脚文本没有固定在页脚顶部,所以我一直在寻找解决方案,但找不到任何地方可以修复它。
我想像这张图片一样排列页脚文本
我该怎么办?
titleForFooterInSection
代码:
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
if section <= 1{
return "5~15자로 작성해주세요"
}else{
return nil
}
}
heightForFooterInSection
+++代码:
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
switch section {
case 0:
return 44
case 1:
return 64
default:
return 0
}
}
我想知道即使这样也会造成这样的问题。
最佳答案
如您所见,标题只是垂直居中对齐。所以如果你想将它对齐到顶部,你需要创建一个自定义页脚。代码可能如下所示。您应该根据自己的情况进行调整。
override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let view = UIView()
view.backgroundColor = UIColor.lightGray
let label = UILabel()
// Note here you should use AutoLayout instead of the frame.
// You may consider using SnapKit.
label.frame = CGRect(x: 20, y: 8, width: 100, height: 10)
if section <= 1 {
label.text = "5~15자로 작성해주세요"
}
view.addSubview(label)
return view
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
switch section {
case 0:
return 44
case 1:
return 64
default:
return 0
}
}
关于ios - UITableView 页脚的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47047220/