在TableViewController中更改UILabel Y位置

时间:2016-06-23 01:59:55

标签: ios uitableview uilabel

我已经UITableViewController了,我在界面构建器的tableview下面放了一个UILabel。但是,我似乎无法控制标签的实际Y位置。桌面视图和标签之间存在很大差距,我希望通过稍微移动标签来减少这种差距。我尝试以编程方式移动标签origin.y,但它仍保留在同一位置。

有没有办法做到这一点?

enter image description here

1 个答案:

答案 0 :(得分:0)

如果您希望它位于表格视图的底部,您只需将其添加为tableFooterView即可。例如:

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

您可以使用添加到UIViewControllerUITableViewController的表格视图。

tableFooterView直接邻接表格视图的最后一部分的页脚。

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