简体   繁体   中英

set button on bottom of static tableView

hello I want to set the programmatically created button at bottom of static tableView . The problem I am having is the botton stays at the bottom on smaller phones(5s) which is completely fine. But on 6s Plus it shows white area underneath the button. Meaning the button is slightly above from the ground or above from edge of the bottom. 在此输入图像描述

This is how I am setting the button

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
}

It sounds like you want a footer at the bottom of the table, rather than at the end of the section. In this case you should use the table's tableFooterView property. You could do this with the following code in viewDidLoad (or elsewhere):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM