使用Playground‘玩’界面 - 1

作者: handyTOOL | 来源:发表于2016-09-11 22:52 被阅读0次

苹果的Playground让开发者可以快速的验证自己的想法,不需要建立一个臃肿的项目,并且全程可视化,你可以知道自己每一步都得到了什么。你可以使用它进行一些算法或者API上的研究,也可以研究动画或者其他UI特性,本文就是介绍如何使用Playground研究UI相关的特性。

这是一个简单的Playground,我们怎样才能让他调试界面呢?如果我们创建一个UIView,该把它放在哪呢?其实很简单,看下面的代码。

import UIKit
import PlaygroundSupport

let simpleView = UIView.init(frame: CGRect.init(x: 0, y: 0, width: 300, height: 450))
simpleView.backgroundColor = UIColor.cyan

PlaygroundPage.current.liveView = simpleView

如果你的Xcode是7之前的版本,需要使用import XCPlayground替代import PlaygroundSupport,相关文档在这Playground Support

通过PlaygroundSupportPlaygroundPage.current.liveView就可以设置当前要显示的View了。效果如下。

记得要打开assistant editor。

如何手动运行Playground

Paste_Image.png

按住左下角的三角按钮,会弹出一个菜单,选择Manually Run就可以手动运行Playground了,以后每次点击三角按钮才会运行Playground。

相关文章

网友评论

    本文标题:使用Playground‘玩’界面 - 1

    本文链接:https://www.haomeiwen.com/subject/obwyettx.html