1

我想知道是否可以创建如下图所示的内容。

在此处输入图像描述

我想我必须创建一个自定义视图,但是关于如何做的任何线索?

谢谢

4

1 回答 1

0

如果屏幕上有 UITableView,可以通过创建自定义表头视图来实现:

  1. 创建UIView->的子类CustomTableHeaderView
  2. 在其中添加一个按钮:

    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")
        } 
    

    }

    1. 在您的视图控制器(或您初始化表格视图的任何其他地方,将您的自定义视图设置为tableHeaderView

    tableView.tableHeaderView = CustomTableHeaderView(frame: frame:CGRect(x: 0, y: 0, width: view.frame.width, height: 10))

于 2016-07-12T15:50:09.787 回答