swift - 如何在swift 5中添加带有一个标签的表格视图页脚
问题描述
我只想在表格视图的末尾添加一个标签。
let customView = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 50))
customView.backgroundColor = UIColor.red
let label = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
label.text = "app version"
customView.addSubview(label)
sideMenuTableView.tableFooterView = customView
我想将 customView 宽度设置为等于主视图的宽度,并且标签应该位于视图的最左角
解决方案
斯威夫特 5
添加 UITableViewDelegate 方法:-
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let footerView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 40))
footerView.backgroundColor = UIColor.yellow
let labelFooter = UILabel(frame: footerView.frame)
labelFooter.text = "Footer view label text."
labelFooter.textColor = .red
footerView.addSubview(labelFooter)
return footerView
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 40
}
推荐阅读
- python-3.x - matplotlib 直方图中的两个轴用于目标的两个问题
- c++ - 在 C++ 中返回 IO 对象的目的是什么?
- c# - 尝试在 Xamarin 中单击按钮时关闭 ViewCell.ContextAction
- python - 将一堆 json 文件存储到数据库中的最佳方法
- flutter - flutter_form_builder 下拉布局修改
- java - 正则表达式模式 - 重复组
- r - 如何在现有数据框的底部加入数据框而不重写整个数据框?
- sql - 声明 postgres 变量时出现语法错误
- dependency-injection - 关于 route.thephpleague.com 的正确 DI 方法
- php - 如何在 Codeception 中使用和不使用 javascript 运行测试?