Xcode Canvas不显示整个页面,只显示部分

dojqjjoe  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(149)

下面是我的代码:

import SwiftUI

struct ContentView: View {
    var body: some View {
        Text("Apps")
            .font(.system(size: 30))
            .fontWeight(.bold)
        Image("utm")
            .resizable()
            .frame(width: 60, height: 60)
        Text("UTM")
            .fontWeight(.bold)
        Text("Virtual machines for macOS")
            .foregroundColor(.gray)
        Button("Get UTM") {
            
        }
            .background(Color(hue: 0.0, saturation: 0.861, brightness: 1.0))
            .controlSize(.large)
            .cornerRadius(25)
        
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

字符串
当我打开canvas时,会发生这样的情况:

如何将其转换成一个单一的内容视图,而不是将所有的片段拆分成?

eoigrqb6

eoigrqb61#

这是因为,在SwiftUI中,视图应该封装在堆栈结构中,如下面提供的示例。

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Apps")
                .font(.system(size: 30))
                .fontWeight(.bold)
            Image("utm")
                .resizable()
                .frame(width: 60, height: 60)
            Text("UTM")
                .fontWeight(.bold)
            Text("Virtual machines for macOS")
                .foregroundColor(.gray)
            Button("Get UTM") {
                
            }
                .background(Color(hue: 0.0, saturation: 0.861, brightness: 1.0))
                .controlSize(.large)
                .cornerRadius(25)
        }
        
    }
}

字符串

相关问题