gpt4 book ai didi

swift - 如何在 Playgrounds 中设置 ViewController?

转载 作者:搜寻专家 更新时间:2023-10-31 21:50:02 25 4
gpt4 key购买 nike

在 swift playgrounds 中,如何设置和使用 View Controller ?我以前用 UIView 做过,但是当方向不同时 UI 会被切断,所以我想尝试使用 viewcontroller。我有 let view = UIViewController() 但在那之后我如何设置它来添加背景和东西?

最佳答案

要在 Swift playground 中创建 View Controller ,您需要以下代码:

import UIKit
import PlaygroundSupport

class ViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
// do setup here
}
}

let viewController = ViewController()
PlaygroundPage.current.liveView = viewController
PlaygroundPage.current.needsIndefiniteExecution = true

关于swift - 如何在 Playgrounds 中设置 ViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43160615/

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