本文介绍了iOS Playground不显示UI预览的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我用XCode 7.1创建了一个简单的游乐场,我输入了这个简单的代码:
import UIKit
import XCPlayground
var str =Hello,playground
let color = UIColor(红色:1,绿色:1,蓝色:0,alpha:0)
让视图= UIView的()
view.backgroundColor = UIColo(colorLiteralRed:1,绿:0,蓝色:0,α-:0)
view.frame = CGRect(x:0,y:0,width:100,height:100)
let label = UILabel(frame:CGRect(x:5,y:5,width:50,height: 20))
label.text = str
view.addSubview(label)
当游乐场运行时,它不显示UIKit对象预览,而只显示调试信息:
我做错了什么?
解决方案
打开预览面板:查看>助理编辑器>显示助理编辑器
然后在您的代码中:
进口PlaygroundSupport
PlaygroundPage.current.liveView =视图
Ps:在Xcode 9之后,你可以用默认视图创建一个游乐场
I've created a simple playground with XCode 7.1 and I've typed this simple code:
import UIKit
import XCPlayground
var str = "Hello, playground"
let color = UIColor (red: 1 , green: 1 , blue: 0 , alpha: 0 )
let view = UIView()
view.backgroundColor = UIColo (colorLiteralRed: 1 , green: 0 , blue: 0 , alpha: 0 )
view.frame = CGRect (x: 0 ,y: 0 ,width: 100 ,height: 100 )
let label = UILabel (frame: CGRect (x: 5 , y: 5 , width: 50 , height: 20 ))
label.text = str
view.addSubview(label)
When the playground runs, it doesn't show UIKit object preview, but only debug information:
What am I doing wrong?
解决方案
Open the preview panel: View > Assistant Editor > Show Assistant Editor
Then in your code:
import PlaygroundSupport
PlaygroundPage.current.liveView = view
Ps: after Xcode 9, you can create a playground with default view
这篇关于iOS Playground不显示UI预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!