答案 0 :(得分:0)
如果屏幕上有UITableView,可以通过创建自定义表头视图来实现:
UIView
的子类 - > CustomTableHeaderView
在其中添加一个按钮:
class CustomTableHeaderView: UIView {
var rightButton: UIButton
override init(frame: CGRect) {
rightButton = UIButton()
let buttonWidth: CGFloat = 100
// this is hardcoded for cimplicity, it's better to setup auto layout constraints here
rightButton.frame = CGRect(x: 0, y: frame.width - buttonWidth, width: buttonWidth, height: 50)
rightButton.setTitle("My button", forState: .Normal)
// other configuration
super.init(frame: frame)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
tableHeaderView
: tableView.tableHeaderView = CustomTableHeaderView(frame: frame:CGRect(x: 0, y: 0, width: view.frame.width, height: 10))