在静态tableView底部设置按钮

时间:2016-03-16 19:38:29

标签: ios swift uitableview tablefooterview

你好我想在静态tableView底部设置以编程方式创建的按钮。我遇到的问题是在较小的手机(5s)底部保持底部,完全没问题。但在6s Plus上它显示按钮下方的白色区域。这意味着按钮略高于地面或从底部边缘的上方。 enter image description here

这就是我设置按钮的方式

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
}

1 个答案:

答案 0 :(得分: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
相关问题