我目前正在向我的应用程序添加一个信息页面,并希望在分组的 UITableView 的页脚中心显示应用程序的版本号。我有它显示,但我不确定如何将它居中。
我看过使用 tableviews viewForFooterInSection;这是前进的正确方法,还是有更简单的方法?
非常感谢。
最佳答案
只需向您的 tableView 添加一个页脚,无论您有多少个部分,它都会放在底部
let tableViewFooter = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.width, height: 50))
tableViewFooter.backgroundColor = UIColor.greenColor()
let version = UILabel(frame: CGRectMake(8, 15, tableView.frame.width, 30))
version.font = version.font.fontWithSize(14)
version.text = "Version 1.x"
version.textColor = UIColor.lightGrayColor()
version.textAlignment = .Center;
tableViewFooter.addSubview(version)
tableView.tableFooterView = tableViewFooter
如果要为每个部分添加页脚
在您的 tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView
中创建一个 UIView()
?方法并将标签添加到该 View 并将标签置于其中居中。
例子:
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let view = UIView()
let version = UILabel(frame: CGRectMake(8, 15, tableView.frame.width, 30))
version.font = version.font.fontWithSize(14)
version.text = "Version 1.x"
version.textColor = UIColor.lightGrayColor()
version.textAlignment = .Center;
view.addSubview(version)
return view
}
关于ios - 分组的 UITableView 中的中心页脚 UILabel - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34070463/