我想知道是否可以创建如下图所示的内容。
我想我必须创建一个自定义视图,但是关于如何做的任何线索?
谢谢
如果屏幕上有 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))