Brosef Brosef - 1 year ago 86
iOS Question

Changing UILabel Y position in TableViewController

I've a

and I placed a
beneath the tableview in interface builder. However, I can't seem to control the actual Y position of the label. There's a big gap between the tableview and the label that I'd like to reduce by moving the label up a bit. I tried moving the labels
programmatically but it remains in the same spot.

Is there any way to do this?

enter image description here

Answer Source

If you want it at the bottom of the table view, you can just add it as the tableFooterView. For example:

    override func viewDidLoad() {
        let footerLabel = UILabel()
        footerLabel.text = "Some Text"
        footerLabel.textAlignment = .Center
        footerLabel.textColor = UIColor.redColor()
        self.tableView.tableFooterView = footerLabel

You can use either a table view added to a UIViewController or a UITableViewController.

The tableFooterView directly abuts the section footer for the last section of the table view.

override func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 0.1 // adjust this value to determine how close the label is to the last table view cell. Don't return 0 unless you want the default value for grouped style table views

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download