D
D
Denis2021-03-29 12:03:39
iOS
Denis, 2021-03-29 12:03:39

How to fill an image in full size so that they are the same size SwiftUi?

Can you tell me why the images are different sizes?
how do i make them the same size?
SwiftUI

6061980c6c4d2124586499.jpeg

code is like this:

TabView(selection: $currentIndex) {
                
                ForEach(1..<numberOfImages) { num in
                    Image("er\(num)")
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        //.scaledToFit()
                        // adding animation...
                        //.frame(height: self.num == num ?  200 : 240)
                        .cornerRadius(15)
                        .overlay(Color.black.opacity(0.4)).cornerRadius(15)
                        // for identifying current index....
                        .tag(num)
                }
                .scaledToFit()
                .aspectRatio(contentMode: .fit)
            }
            .frame(height: 200)
            .tabViewStyle(PageTabViewStyle())

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2021-04-02
@kozinakoff

Apparently you have images of different sizes. In this case, you need to specify that the image "fills" all the available space (.aspectRatio(contentMode: .fill)):

TabView(selection: $currentIndex) {
            
            ForEach(1..<numberOfImages) { num in
                Image("er\(num)")
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(height: 200)
                    .cornerRadius(15)
                    .overlay(Color.black.opacity(0.4)).cornerRadius(15)
                    .padding([.leading, .trailing], 10)
                    .tag(num)
            }
        }
        .frame(height: 200)
        .tabViewStyle(PageTabViewStyle())
        .padding()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question