ios - swift 4 UITableView 页脚,绝对底部
问题描述
我为我的 UITableView 创建了一个页脚,如下所示:
let customView = UIView(frame: CGRect(x: 0, y: self.view.bounds.height - 50, width: self.view.bounds.width, height: 50))
customView.backgroundColor = UIColor.red
commentText = UITextField(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width - 50, height: 50))
commentText.backgroundColor = UIColor.white
commentText.layer.borderColor = UIColor.gray.cgColor
commentText.layer.borderWidth = 1
commentText.borderStyle = .roundedRect
commentText.placeholder = "Enter Comment"
let submitButton = UIButton(frame: CGRect(x: self.tableView.bounds.width - 50, y: 0, width: 50, height: 50))
submitButton.setTitle("Go", for: .normal)
submitButton.backgroundColor = UIColor.blue
submitButton.addTarget(self, action: #selector(self.submitButtonPressed(_:)), for: .touchUpInside)
customView.addSubview(commentText)
customView.addSubview(submitButton)
tableView.tableFooterView = customView
这是屏幕截图中的结果:
我想要做的是让页脚始终位于屏幕底部,这可能吗?
解决方案
表格视图页脚始终位于表格视图的末尾,在表格视图的最后一行之后。无论表格视图中有多少行,这都是正确的。
如果您想要一个保持在屏幕底部并且无论有多少行都不会滚动的视图,那么您不需要表格视图页脚。您只需要将视图添加到屏幕底部。
最好的解决方案是使用一个UIViewController
将“页脚视图”固定在底部并添加一个表格视图来填充屏幕的其余部分。
推荐阅读
- php - 在php中获取数组项的名称
- python - 如何在 Pygame 中克隆 Sprite?
- android - 无法在 Kotlin 多平台项目中调试 iOS 应用程序
- keycloak - 注册后如何在keycloak用户模型中存储外部数据
- drake - 如何在 Drake 中更改 RevoluteJoint 的阻尼系数
- apache-spark - 在 spark scala 中参数化的 lit() 函数
- c++ - 将模板函数指针转换为通用类型
- python-3.x - 使用 cross_val_score() 时输入包含 NaN 错误
- flutter - 将初始值传递给 Cubit
- python - 从复杂字符串中解析出与给定模式匹配的子字符串