-1

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: enter image description here

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

enter image description here

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!

Hiren Faldu
  • 127
  • 1
  • 4

0 Answers0