Learn Courses My Dashboard

First community post... first question. Images not displaying correctly

Hello All,

It’s great to be here!

I have been looking for 2 days, but haven’t found the answer to this yet, so I figured it would make a great first question.

My three “SwiftUI Slots” images are bigger than the iPhone screen. For some reason they aren’t scaling to fit the correct width and half of the first and third images are cut off. I’m guessing that the bigger images are being chosen instead of the smaller pictures. Could someone point me in the right direction please?

Many thanks!
Matt

Hi,

Can you post your code?
( when my pictures are not in the correct size, I usually forgot to add .resizable() )

1 Like

Hi Wildsparrow,

You were right, I hadn’t added .resizable().

However, now that I have added it the width is taken care of, but the images are stretched really tall.

It’s strange, because I didn’t have to do any of this on my “War card game” app. Is there a way to take care of height too?

1 Like

To get the images to maintain the right aspect ratio you can use either .aspectRatio(contentMode: .fit) or you can use .scaledToFit().

2 Likes

Hello Chris,

Thank you for your reply!

After trying a few options I have found that a combo of .resizable() and .aspectRatio(contentMode: .fit) got me to where I need to be.

Many thanks for your help guys!
Matt

2 Likes