【发布时间】:2016-12-15 11:44:50
【问题描述】:
【问题讨论】:
-
此按钮是否需要随表格视图滚动或始终保持可见?
标签: swift uitableview button
【问题讨论】:
标签: swift uitableview button
你可以试试这个。
let bottomButton = UIButton(frame: CGRect(x: 100, y: 300, width: 100, height: 30))
bottomButton.setTitle("Enter Text Here", for: .normal)
bottomButton.backgroundColor = UIColor.orange
view.addSubview(bottomButton)
您可以根据视图控制器设置 x、y 位置。另外,根据tableViewController的宽高设置宽高。
【讨论】:
如果您想要一个简单的解决方案,您有两种选择:
1.创建一个带有按钮的页脚视图,然后使用以下方法将此页脚添加到您的表格视图中:
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView?
和
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat
此解决方案将使您的按钮随表格视图滚动
2。使用UIViewController 而不是UITableViewController:
UITableViewDelegate 和UITableViewDataSource
tableView.delegate = self和tableView.dataSource = self
使用此解决方案,您的按钮将始终停留在屏幕上,并且只有表格视图会滚动
【讨论】: