Xcode 游乐场中的 SwiftUI 问题,Xcode 12.4

problem in Xcode playground with SwiftUI , Xcode 12.4

实时视图显示一个小方框,刚好适合文本或视图内的任何内容,它不会显示完整 phone

这是代码

@State private var favoriteColor = "Red"
var colors = ["Red", "Green", "Blue"]

var body: some View {
    VStack{
        Picker(selection: $favoriteColor, label: Text("hey")) {
                Text("hey2")
        }
        .pickerStyle(SegmentedPickerStyle())
        Text("\(favoriteColor)")
    }
} 

here is how the live view looks

在您所附的图片中,您显示了一些您实际上并未包含在您的问题中的代码。在其中,您将 UIHostingController 初始化为一定大小,但之后从不对其进行任何操作——相反,您将 playground 视图设置为 ContentView.

您可以通过向其添加 frame 修饰符使 ContentView 以更大的边框显示:

PlaygroundPage.current.setLiveView(ContentView().frame(width: 375, height: 667))