.scaledToFit()
The .scaledToFit()
modifier method scales a view to fit its parent view while maintaining the original aspect ratio.
Syntax
Image("image-file")
.scaledToFit()
The .scaledToFit()
modifier takes no parameters and returns the view scaled with the original aspect ratio.
Example
In the example below, the .scaledToFit()
modifier is applied on an image:
import SwiftUIstruct MyStructure: View {var body: some View {Image("imagename").resizable().scaledToFit()}}
This will display the following:
The image is scaled down in the example above with the .scaledToFit()
modifier to fit the width of the parent view. The original aspect ratio of the image is maintained.
All contributors
- CJSdeHaas1 total contribution
- cslylla58 total contributions
- Christine_Yang271 total contributions
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.