[英]Question about putting a fixed button in a static tableviewController in Swift
您应该为tableView
创建一个页脚视图来执行此操作。
以编程方式
let footerView = UIView()
footerView.backgroundColor = .red // your color
// You have to give height and width yourself
let button = UIButton(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
button.setTitle("<title>", for: .normal)
button.addTarget(self, action: #selector(didTapButton), for: .touchUpInside)
footerView.addSubview(button)
通过接口生成器
只需将UIView
( CMD + Shift + L
> type uiview) 拖放到 tableView 中,然后将按钮添加到footerView
,设置约束。
然后你应该把这个footerView
添加到你的tableView
tableView.tableFooterView = footerView
为你的按钮创建一个动作
@objc func didTapButton(_ sender: UIButton) {
print("didTapButton called")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.