iOS Playground doesn#39;t show UI preview(iOS Playground 不显示 UI 预览)
问题描述
我使用 XCode 7.1 创建了一个简单的 Playground,并且输入了以下简单代码:
导入 UIKit导入 XCPlaygroundvar str = "你好,游乐场"让 color = UIColor (red: 1 , green: 1 , blue: 0 , alpha: 0 )让视图 = 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 ))标签.text = strview.addSubview(标签)
playground 运行时不显示 UIKit 对象预览,只显示调试信息:
我做错了什么?
打开预览面板:View > Assistant Editor > Show Assistant Editor
然后在你的代码中:
导入 PlaygroundSupportPlaygroundPage.current.liveView = 查看
<块引用>
别忘了给你的视图一个可见的框架.
<小时>
Ps:在 Xcode 9 之后,你可以创建一个默认视图的 Playground
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
Don't forget to give your view a visible frame.
Ps: after Xcode 9, you can create a playground with default view
这篇关于iOS Playground 不显示 UI 预览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS Playground 不显示 UI 预览
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01