如何将 UITextView 放在 TableViewController 的底部?
How to put a UITextView at the bottom of the TableViewController?
我想知道将 UITextView 放在 TableViewController 底部的正确方法是什么,我不希望它放在单元格中,因为我已经知道该怎么做,但那不是我正在尝试做,我想在 tableViewController
的底部放置一个 UITextView
class ExampleTableViewController: UITableViewController, UITextViewDelegate {
let firstView = UITextView()
first.translatesAutoresizingMaskIntoConstraints = false
func setUpTextView() {
firstView.delegate = self
view.addSubview(firstView)
NSLayoutConstraint.activate([firstView.topAnchor.constraint(equalTo: view.topAnchor),
firstView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
firstView.leftAnchor.constraint(equalTo: view.leftAnchor),
firstView.rightAnchor.constraint(equalTo: view.rightAnchor)])
} }
替换
firstView.topAnchor.constraint(equalTo: view.topAnchor)
和
firstView.heightAnchor.constraint(equalToConstant:50)
由于 table 控制器的视图是 table 视图,因此添加的任何视图都将随之滚动,因此最好创建
class ExampleTableViewController: UIViewController, UITextViewDelegate {
一个普通的 vc 与 tableView && textView with constraints set properly
编辑: 所以要么实施 scrollViewDidScroll
并将底部约束更改为 table 为 tableView.contentOffset.y
或
将视图设置为页脚,例如
self.tableView.footerView = firstView
我想知道将 UITextView 放在 TableViewController 底部的正确方法是什么,我不希望它放在单元格中,因为我已经知道该怎么做,但那不是我正在尝试做,我想在 tableViewController
的底部放置一个 UITextView class ExampleTableViewController: UITableViewController, UITextViewDelegate {
let firstView = UITextView()
first.translatesAutoresizingMaskIntoConstraints = false
func setUpTextView() {
firstView.delegate = self
view.addSubview(firstView)
NSLayoutConstraint.activate([firstView.topAnchor.constraint(equalTo: view.topAnchor),
firstView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
firstView.leftAnchor.constraint(equalTo: view.leftAnchor),
firstView.rightAnchor.constraint(equalTo: view.rightAnchor)])
} }
替换
firstView.topAnchor.constraint(equalTo: view.topAnchor)
和
firstView.heightAnchor.constraint(equalToConstant:50)
由于 table 控制器的视图是 table 视图,因此添加的任何视图都将随之滚动,因此最好创建
class ExampleTableViewController: UIViewController, UITextViewDelegate {
一个普通的 vc 与 tableView && textView with constraints set properly
编辑: 所以要么实施 scrollViewDidScroll
并将底部约束更改为 table 为 tableView.contentOffset.y
或
将视图设置为页脚,例如
self.tableView.footerView = firstView