I want to achieve this (For the screenshots I used constant heights, just to visualize what I am looking for):
The two Views
containing text should together have the same height as the (blue) Image
View. The right and left side should also be of the same width. The important part: The Image
View can have different aspect ratios, so I can't set a fixed height for the parent View. I tried to use a GeometryReader
, but without success, because when I use geometry.size.height
as height, it takes up the whole screen height.
This is my code:
import SwiftUI
struct TestScreen: View {
var body: some View {
VStack {
GeometryReader { geometry in
HStack {
Image("blue-test-image")
.resizable()
.scaledToFit()
.frame(maxWidth: .infinity)
VStack {
Text("Some Text")
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.gray)
Text("Other Text")
.padding()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.gray)
}
.frame(maxWidth: .infinity, maxHeight: geometry.size.height /* should instead be the height of the Image View */)
}
}
Spacer()
}
.padding()
}
}
This is a screenshot of what my code leads to:
Any help would be appreciated, thanks!