如何在 Playgrounds 中设置 ViewController? [英] How to setup ViewController in Playgrounds?

查看:33
本文介绍了如何在 Playgrounds 中设置 ViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 swift playgrounds 中,您如何设置视图控制器并使用它?我以前用 UIView 完成过,但是当处于不同方向时 UI 会被剪切,所以我想尝试使用视图控制器.我有 let view = UIViewController() 但在那之后我如何设置它以添加背景和内容?

In swift playgrounds how do you setup a viewcontroller and use it? I've done it with a UIView before but the UI gets cut when in a difference orientation so I want to try use a viewcontroller. I've got let view = UIViewController() but after that how do I set it up to add a background and stuff on it?

推荐答案

我发现要在 swift playground 中创建视图控制器,您需要此代码

I found that to create a viewcontroller in swift playgrounds you need this code

import UIKit
import PlaygroundSupport

class ViewController:UIViewController{
    override func viewDidLoad() {
        super.viewDidLoad()

    }

}

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

这篇关于如何在 Playgrounds 中设置 ViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆