SwiftUI Image – Corner Radius
To set corner radius for Image, add cornerRadius()
modifier to the Image view. The cornerRadius()
modifier takes radius value fo type CGFloat as argument.
Example
In this example, we shall display an image from assets in two Image views with different corner radii. The first Image shall have a corner radius of 10 while the the second Image shall have a corner radius of 20.
ContentView.swift
import SwiftUI
struct ContentView: View {
var body: some View {
Image("sunrise")
.resizable()
.aspectRatio(contentMode: .fit)
.cornerRadius(10.0)
.padding(.all, 50)
Image("sunrise")
.resizable()
.aspectRatio(contentMode: .fit)
.cornerRadius(20.0)
.padding(.all, 50)
}
}
Screenshot

Summary
Summarising thisĀ SwiftUI Tutorial, we learned how to set corner radius for an Image using SwiftUI.