首页 > 解决方案 > 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

这是屏幕截图中的结果:

在此处输入图像描述

我想要做的是让页脚始终位于屏幕底部,这可能吗?

标签: iosswiftuitableview

解决方案


表格视图页脚始终位于表格视图的末尾,在表格视图的最后一行之后。无论表格视图中有多少行,这都是正确的。

如果您想要一个保持在屏幕底部并且无论有多少行都不会滚动的视图,那么您不需要表格视图页脚。您只需要将视图添加到屏幕底部。

最好的解决方案是使用一个UIViewController将“页脚视图”固定在底部并添加一个表格视图来填充屏幕的其余部分。


推荐阅读