繁体   English   中英

VStack 不适合 ContentView SwiftUI

[英]VStack is not fitting in ContentView SwiftUI

我用 SwiftUI 创建了一个应用程序我已经使用此代码来布局我的视图

struct ContentView: View {
    var body: some View {
        List(0 ..< 5) { item in
            VStack {
                Text("Hello World")
                    .font(.largeTitle)
                    .fontWeight(.bold)
                    .foregroundColor(Color.red)
                Image("Hello")
                    .aspectRatio(contentMode: .fit)
            }
        }
    }
}

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

但 VStack 不适合 contentView

在此处输入图像描述

只需将.resizable() 添加到您的图像中。

在它周围包裹一个 ScrollView{}。

struct ContentView: View {
var body: some View {
    List(0 ..< 5) { item in
      ScrollView{
        VStack {
            Text("Hello World")
                .font(.largeTitle)
                .fontWeight(.bold)
                .foregroundColor(Color.red)
            Image("Hello")
                .aspectRatio(contentMode: .fit)
        }
      }
    }
  }
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM