D
D
Denis2021-03-26 00:28:55
iOS
Denis, 2021-03-26 00:28:55

How to display images horizontally in one line SWIFTUI?

How to change the display of images in one line horizontally and not vertically as it is now (

605d00470a3eb282751934.jpeg

Now the code is this:

//I1
            HStack {
                VStack(alignment: .leading) {
                    Image(champions.imagei1)
                        .resizable()
                        .scaledToFit()
                        .aspectRatio(1, contentMode: .fit)
                    
                                }
                .frame(width: 60, height: 60)
            }
            
            //I2
            VStack(alignment: .leading) {
                Image(champions.imagei2)
                    .resizable()
                    .scaledToFit()
                    .aspectRatio(1, contentMode: .fit)
                            }
                            .frame(width: 60, height: 60)
            
            //I3
            VStack(alignment: .leading) {
                Image(champions.imagei3)
                    .resizable()
                    .scaledToFit()
                    .aspectRatio(1, contentMode: .fit)
                            }
                            .frame(width: 60, height: 60)
            
            
            
        }.frame(minWidth: 0, idealWidth: 0, maxWidth: .infinity, minHeight: 0, idealHeight: 0, maxHeight: .infinity, alignment: .topLeading)
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2021-04-01
@denmeln

If I understand you correctly:

HStack {
            Image(champions.imagei1)
                .resizable()
                .scaledToFit()
                .aspectRatio(1, contentMode: .fit)
                .frame(width: 60, height: 60)
            
            Spacer()
            
            Image(champions.imagei2)
                .resizable()
                .scaledToFit()
                .aspectRatio(1, contentMode: .fit)
                .frame(width: 60, height: 60)
                    
            Spacer()
            
            Image(champions.imagei3)
                .resizable()
                .scaledToFit()
                .aspectRatio(1, contentMode: .fit)
                .frame(width: 60, height: 60)
      
        }.padding()

HStack - a container in which child elements are arranged horizontally.
VStack - vertically, respectively.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question