gpt4 book ai didi

Swift:创建导致新 View 的按钮

转载 作者:行者123 更新时间:2023-11-30 13:43:43 24 4
gpt4 key购买 nike

我想知道如何以编程方式在不使用 Storyboard的情况下制作一个按钮,按下该按钮会引导您进入另一个 View Controller 。

最佳答案

let button = UIButton(type: UIButtonType.System)
button.setTitle("Button", forState: UIControlState.Normal)
button.sizeToFit()
button.addTarget(self, action: "loadViewController", forControlEvents: UIControlEvents.TouchUpInside)
self.view.addSubview(button)

loadViewController 是 Controller 中加载另一个 View Controller 的方法。

func loadViewController()
{
let vc = UIViewController(nibName: "ViewController", bundle: nil)
self.presentViewController(vc, animated: true, completion:nil)
}

关于Swift:创建导致新 View 的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35237802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com