Question
How to make Image center of the screen and below it a label in swiftUI
I am working on a simple design in SwiftUI, but I am finding it quite challenging. Here is the design I am trying to achieve:
the design seems to be easy but unfortunately it very challenging in swift The goal is to center an image with a height and width of 140 points in the middle of the screen. Below the image, there should be a text label with a top padding of 50 points. Here is the code I have so far:
struct ContentView: View {
var body: some View {
VStack {
Spacer()
VStack(spacing: 0) {
Image("SwiftLogo")
.resizable()
.scaledToFit()
.frame(width: 140, height: 140)
Text("Hello Swift")
.font(.system(size: 32, weight: .semibold))
.foregroundColor(.black)
.background(Color.green)
.padding(.top, 50)
}
Spacer()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.edgesIgnoringSafeArea(.all)
}
}
However, this code centers the entire view, which is not what I want. How can I modify it to achieve the desired design?
The goal is to center an image with a height and width of 140 points in the middle of the screen. Below the image, there should be a text label with a top padding of 50 points.