【问题标题】:Creating a segue programmatically without a storyboard在没有情节提要的情况下以编程方式创建 segue
【发布时间】:2017-10-19 01:00:45
【问题描述】:

尝试为我的注册按钮创建一个 segue,该按钮会将用户发送到允许他们在我的数据库中注册的页面。

通常,我为我的按钮制作一个按钮和一个目标,它通过一个函数执行一些操作。

我们可以让这个函数转场 PROGRAMMATICALLY 请注意我根本没有使用故事板?

代码片段:

 lazy var registerButton: UIButton = {

    let rButton = UIButton(type: .system)

     rButton.frame = CGRect(x: 210, y: 600, width: 100, height: 50)

    rButton.setTitle("REGISTER", for: .normal)
    rButton.backgroundColor = UIColor.white
    rButton.translatesAutoresizingMaskIntoConstraints = false
    rButton.setTitleColor(UIColor.black, for: .normal)
    rButton.titleLabel?.font = UIFont.boldSystemFont(ofSize: 20)

    rButton.layer.cornerRadius = 20
    rButton.layer.borderWidth = 2

    rButton.addTarget(self, action: #selector(regSegue), for: .touchUpInside)

    return rButton
}()

// will segue for me
func regSegue(){

}

【问题讨论】:

标签: ios swift uistoryboardsegue


【解决方案1】:

我假设您的意思是 ViewControllerpage 一词。所以在你的func regSegue(){...} 中初始化你的ViewController 并使用present(_:animated:completion:) 方法呈现它。

例子:

func regSegue(){
    let page = PageViewController()
    present(page, animated: true, completion: nil)
}

【讨论】:

  • 我该怎么做
  • 还有一个问题,我可以向这个新页面添加 inputContainer 视图和按钮
  • 想通了!
  • 如何将背景颜色改为白色
  • 您需要为其他查询发布另一个问题。但首先尝试在 Stack Overflowgoogle search 中搜索。您会发现很多关于如何更改背景颜色的问题和答案。
【解决方案2】:

您可以在没有故事板的情况下轻松实现这一点。首先,您需要初始化需要显示的视图控制器。然后呈现视图控制器。

 let vc: MyViewController = MyViewController()
 self.presentViewController(vc, animated: true, completion: nil)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多