|

How to Add Image with Rounded Corners in iOS SwiftUI

An image is considered as one of the important UI elements of a mobile app. Let’s learn how to add an image with rounded corners in the iOS app using SwiftUI.

I already posted a tutorial on how to add images in iOS. Firstly, create a new iOS app project using Xcode. Then drag and drop an image to the assets folder of your project.

Open ContentView.swift and delete the existing code. You can use Image with cornerRadius modifier to make the corners round. Add the following code to your project.

import SwiftUI

struct ContentView: View {
    var body: some View {
        Image("animal")
            .resizable()
            .cornerRadius(20)
            .aspectRatio(contentMode: .fit)
            .padding(10)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

See the output given below.

swiftui image with rounded corners

That’s how you add an image with border-radius in iOS using SwiftUI. I hope you enjoyed this tutorial.

Similar Posts

Leave a Reply