你如何在 Xcode 8/Swift 3 中创建一个 iOS liveView [英] How do you create an iOS liveView in Xcode 8/Swift 3
问题描述
我不知道如何在 Xcode 8/Swift 3 Playground 中创建和显示实时视图.如果 Apple 有关于 Playgrounds 和实时视图的全面文档,我找不到它,而且我所有的在线搜索都会显示 Xcode 7 或新 iPad Playground 的教程.我发现的几个示例设置了 Mac OS 视图,这不是我想要的(我主要在 iOS 上工作,所以我想测试的代码是 iOS 代码,处理 iOS 视图层次结构.)
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 操场安装到其中吗?
Can somebody give me the bare minimum setup to create a live view and install views into it from an Xcode 8 playground?
那么,有人可以向我指出一些关于 Playgrounds 的好文档,以及您如何配置和使用它们吗?
Then, can somebody point me to some good documentation on playgrounds, and how you configure and use them?
推荐答案
它是这样工作的:
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
不幸的是,我不知道一个好的文档.但我相信 Erica Sadun 有一本关于 Playgrounds 的书.
Unfortunately I'm not aware of a good documentation. But I believe there is a book by Erica Sadun about Playgrounds.
这篇关于你如何在 Xcode 8/Swift 3 中创建一个 iOS liveView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!