我不知道如何更改Live View frame
Swift 游乐场中的大小。这是我的代码:
public struct PlaygroundRootView: View {
public var body: some View {
Rectangle()
.frame(width: 200, height: 100, alignment: .center)
.foregroundColor(Color.blue.opacity(0.7))
.cornerRadius(20)
}
}
PlaygroundPage.current.liveView = UIHostingController(rootView: PlaygroundRootView())
我想让Live View
它变宽,改变它的大小。
您需要定义preferredContentSize
的UIHostingController
,如下所示:
import PlaygroundSupport
import SwiftUI
public struct PlaygroundRootView: View {
public var body: some View {
Rectangle()
.frame(width: 200, height: 100, alignment: .center)
.foregroundColor(Color.blue.opacity(0.7))
.cornerRadius(20)
}
}
let host = UIHostingController(rootView: PlaygroundRootView())
host.preferredContentSize = CGSize(width: 600, height: 600)
PlaygroundPage.current.liveView = host
结果
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句