简体   繁体   中英

VStack is not fitting in ContentView SwiftUI

I created a app with SwiftUI I have used this code to layout my view

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()
    }
}

but VStack is not fit to contentView

在此处输入图像描述

Just add.resizable() to your Image.

wrap a ScrollView{} around it.

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()
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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