如何在Xcode 8 / Swift 3中创建iOS liveView [重复]

时间:2023-01-23 19:17:25

This question already has an answer here:

这个问题在这里已有答案:

I can't figure out how to create and display a live view in an Xcode 8/Swift 3 Playground. If Apple has comprehensive documentation on playgrounds and live views, I can't find it, and all my searching online reveals either tutorials on Xcode 7 or the new iPad playgrounds. The few examples I have found set up Mac OS views, which is not what I want (I work mostly in iOS, so the code I want to test out is iOS code, dealing with iOS view hierarchies.)

我无法弄清楚如何在Xcode 8 / Swift 3 Playground中创建和显示实时视图。如果Apple有关于游乐场和实时视图的全面文档,我找不到它,我在网上的所有搜索都会显示Xcode 7上的教程或新的iPad游乐场。我发现的几个例子设置了Mac OS视图,这不是我想要的(我主要在iOS工作,所以我要测试的代码是iOS代码,处理iOS视图层次结构。)

Can somebody give me the bare minimum setup to create a live view and install views into it from an Xcode 8 playground?

有人可以给我一个最小的设置来创建一个实时视图并从Xcode 8游乐场安装视图吗?

Then, can somebody point me to some good documentation on playgrounds, and how you configure and use them?

那么,有人可以指出我在游乐场上的一些好的文档,以及你如何配置和使用它们?

1 个解决方案

#1


5  

It works like this:

它的工作原理如下:

import UIKit
import PlaygroundSupport

let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
view.backgroundColor = UIColor.red

PlaygroundPage.current.liveView = view

Unfortunately I'm not aware of a good documentation. But I believe there is a book by Erica Sadun about Playgrounds.

不幸的是,我不知道一个好的文档。但我相信Erica Sadun有一本关于Playgrounds的书。

#1


5  

It works like this:

它的工作原理如下:

import UIKit
import PlaygroundSupport

let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50))
view.backgroundColor = UIColor.red

PlaygroundPage.current.liveView = view

Unfortunately I'm not aware of a good documentation. But I believe there is a book by Erica Sadun about Playgrounds.

不幸的是,我不知道一个好的文档。但我相信Erica Sadun有一本关于Playgrounds的书。