Swift 如何在表单标题中创建自定义视图

Swift 如何在表单标题中创建自定义视图,swift,eureka-forms,Swift,Eureka Forms,我想知道是否有可能创建类似下图的内容 我想我必须创建一个自定义视图,但有没有关于如何创建的线索 谢谢如果屏幕上有UITableView,您可以通过创建自定义表头视图来实现这一点: 创建UIView->CustomTableHeaderView 在其中添加一个按钮: class CustomTableHeaderView: UIView { var rightButton: UIButton override init(frame: CGRect) { right

我想知道是否有可能创建类似下图的内容

我想我必须创建一个自定义视图,但有没有关于如何创建的线索


谢谢

如果屏幕上有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(帧:帧:CGRect(x:0,y:0,宽度:view.frame.width,高度:10))


    如果屏幕上有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(帧:帧:CGRect(x:0,y:0,宽度:view.frame.width,高度:10))