I have 2 images with different dimensions, When I place them in HStack, the image with bigger dimension takes more space, I want both of them to have equal width.
I tried below code
struct HStackDemo: View {
var body: some View {
HStack {
Image("image2")
.resizable()
.scaledToFill()
.frame(maxWidth: .infinity)
.clipped()
Image("image1")
.resizable()
.scaledToFill()
.frame(maxWidth: .infinity)
.clipped()
}
}
}
And image with bigger dimension taking more space:
If I specify exact width, I am getting expected result
struct HStackDemo: View {
var body: some View {
HStack {
Image("image2")
.resizable()
.scaledToFill()
.frame(width: 183.5)
.clipped()
Image("image1")
.resizable()
.scaledToFill()
.frame(width: 183.5)
.clipped()
}
}
}
But calculating width manually appears to be a patchwork solution to me. Is there any way I can have expected result without giving exact width ?
Thanks in advance!