AndiAna
AndiAna

Reputation: 964

How do you round corners of an image in a Widget (SwiftUI)?

I am simply trying to round the corners of an image.

In the main App it works perfectly fine

Image("dummy-image")
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: 150, height: 150, alignment: .top)
                .cornerRadius(15)

will result in an image with rounded corners.

But when i use the same in a Medium widget where i have it in side a VStack it won't work. I can't find any documentation on how to achieve this.

Try add this section of code to a brand new default app where you have added the widget extension. Add this code to the main "Hello World" section and to the widget View choosing the Large Widget.

HStack(){
    Image("dummy-image")
        .resizable()
        .frame(width: 250, height: 250)
        .clipShape(Capsule())
    //Text(entry.date, style: .time)
}

It will work in the main app. but won't work in the widget...

Upvotes: 3

Views: 2676

Answers (1)

Yrb
Yrb

Reputation: 9725

Have you tried .clipShape(RoundedRectangle(cornerRadius: 20))?

Upvotes: 4

Related Questions