Skip to content
Join us for Free for Full Access to site Content

SwiftUI Image

SwifUI Image is a view that displays an environment-dependent image.

How to display Image from Assets in SwiftUI

It is simple to display an image that is inside assets. Drop your image to the assets catalogue and after that call Image(_:) with the name of the image.

var body: some View {
       <span class="code-line-container" data-v-6334be62=""><span class="code-line" data-v-6334be62=""> <span class="syntax-type">Image</span>(<span class="syntax-string">"yourImage"</span>)</span></span>         
    }

How to load Image from Bundle in SwiftUI

If you want to load the image from Bundle in Swift UI, you can use this code:

This content is for members only. Login or Register to read

How to fit SwiftUI Image

By default, if you call Image(_:) it will not fit the screen. If you need to fit the screen add this code.

var body: some View {
       <span class="code-line-container" data-v-6334be62=""><span class="code-line" data-v-6334be62=""><span class="syntax-type">Image</span>(<span class="syntax-string">"yourImage"</span>)</span></span><span class="code-line-container" data-v-6334be62=""><span class="code-line" data-v-6334be62="">.resizable()         
    }</span></span>

If you want to keep the proportions, just call scaledToFit() to fit the parent. You can also try calling .aspectRatio(contentMode: .fit).

var body: some View {
       <span class="code-line-container" data-v-6334be62=""><span class="code-line" data-v-6334be62=""><span class="syntax-type">Image</span>(<span class="syntax-string">"yourImage"</span>)</span></span><span class="code-line-container" data-v-6334be62=""><span class="code-line" data-v-6334be62="">.resizable()
       .scaledToFit()        
    }</span></span>

You can also call scaledToFill() if it is OK for your app.

How to load SF Symbol SwiftUI Image

This content is for members only. Login or Register to read

 

Learn more about SwiftUI using SwiftUI Tutorials by the AppMakers

If anything will change in the future, it is OK, you can always check the official documentation.

Image Documentation

Leave a comment to Submit the NEW and USEFUL code related to the topic of this post.
Submit a brief and useful code only.

Back To Top
Search

Get Latest App Development News, Tips and Tutorials

* indicates required


Send this to a friend