1

你好,我想在 static 的底部设置以编程方式创建的按钮tableView。我遇到的问题是 botton 在较小的手机(5s)上停留在底部,这完全没问题。但在 6s Plus 上,它在按钮下方显示白色区域。这意味着按钮略高于地面或高于底部边缘。在此处输入图像描述

这就是我设置按钮的方式

func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView?

    let footerView = UIView()
    footerView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 50)
    footerView.backgroundColor = UIColor.redColor()

    let buttonNext = UIButton(type: UIButtonType.System)
    buttonNext.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 50)
    buttonNext.translatesAutoresizingMaskIntoConstraints = false
    buttonNext.setTitle("NEXT", forState: UIControlState.Normal)
    buttonNext.backgroundColor = UIColor.blueColor()

    footerView.addSubview(buttonNext)

    footerView.layoutIfNeeded()
    return footerView

}

func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 50
}
4

1 回答 1

0

听起来您希望在表格底部而不是在该部分的末尾有一个页脚。在这种情况下,您应该使用表的tableFooterView属性。viewDidLoad您可以在(或其他地方)使用以下代码执行此操作:

let footerView = UIView()
footerView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 50)
footerView.backgroundColor = UIColor.redColor()

let buttonNext = UIButton(type: UIButtonType.System)
buttonNext.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 50)
buttonNext.translatesAutoresizingMaskIntoConstraints = false
buttonNext.setTitle("NEXT", forState: UIControlState.Normal)
buttonNext.backgroundColor = UIColor.blueColor()
tableView.tableFooterView = footerView
于 2016-03-16T23:50:45.517 回答