问题描述
借助PreviewProvider
,XCode with可以在Canvas上预览许多环境和设备上的SwiftUI代码。
像这样:
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
ContentView()
.environment((\.horizontalSizeClass),.compact)
ContentView()
.previewDevice(PreviewDevice(stringLiteral: "iPad8,5"))
.environment((\.horizontalSizeClass),.regular)
}
}
}
我们如何在Playground中做同样的事情?以下.previewDevice()
修饰符在Playground(XCode 12.0.1)中无效。
PlaygroundPage.current.setLiveView(ContentView().previewDevice(PreviewDevice(stringLiteral: "iPhone 7")))
也许可以用PlaygroundPage.current.liveView
来完成它吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)