swiftui circular image in swift

To create a circular image in SwiftUI, you can use the Circle shape with an Image inside it. Here's an example code snippet to achieve a circular image:

main.swift
import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack {
            Image("your_image_name") // Replace "your_image_name" with the name of your image asset
                .resizable()
                .scaledToFit()
                .frame(width: 150, height: 150)
                .clipShape(Circle())
        }
    }
}

350 chars
15 lines

In the above code, we first load an image with its name, set it to be resizable, and defined its frame. Then, we use the clipShape modifier with Circle() to clip the image into a circular shape.

Make sure to replace "your_image_name" with the actual name of your image asset.

This code snippet can be used in a SwiftUI view to display a circular image.

related categories

gistlibby LogSnag