在 TableViewController 中更改 UILabel Y 位置
Changing UILabel Y position in TableViewController
我有一个 UITableViewController
并且我在界面生成器中的表格视图下方放置了一个 UILabel
。但是,我似乎无法控制标签的实际 Y 位置。 tableview 和标签之间有很大的差距,我想通过将标签向上移动一点来缩小。我尝试以编程方式移动标签 origin.y
但它仍然在同一个位置。
有什么办法吗?
如果您希望它位于 table 视图的底部,您可以将其添加为 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
}
您可以使用添加到 UIViewController
或 UITableViewController
的 table 视图。
tableFooterView
直接邻接 table 视图最后一部分的部分页脚。
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
}
我有一个 UITableViewController
并且我在界面生成器中的表格视图下方放置了一个 UILabel
。但是,我似乎无法控制标签的实际 Y 位置。 tableview 和标签之间有很大的差距,我想通过将标签向上移动一点来缩小。我尝试以编程方式移动标签 origin.y
但它仍然在同一个位置。
有什么办法吗?
如果您希望它位于 table 视图的底部,您可以将其添加为 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
}
您可以使用添加到 UIViewController
或 UITableViewController
的 table 视图。
tableFooterView
直接邻接 table 视图最后一部分的部分页脚。
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
}