Updated for Xcode 14.0 beta 1
Image view has the ability to be scaled in different ways, just like the content mode of a
By default, image views automatically size themselves to their contents, which might make them go beyond the screen. If you add the
resizable() modifier then the image will instead automatically be sized so that it fills all the available space, either in a frame you specify or whatever is available on the screen:
Image("rome") .resizable() .frame(height: 200)
However, that may also cause the image to have its original aspect ratio distorted, because it will be stretched in all dimensions by whatever amount is needed to make it fill the space.
If you want to keep its aspect ratio you should add an
aspectRatio modifier using either
.fit, like this:
Image("rome") .resizable() .aspectRatio(contentMode: .fit) .frame(width: 250)
SPONSORED You know StoreKit, but you don’t want to do StoreKit. RevenueCat makes it easy to deploy, manage, and analyze in-app subscriptions on iOS and Android so you can focus on building your app.
Link copied to your pasteboard.