how can I add a border with a cornerRadius
to an Image. I get a deprecation warning saying that i should use a RoundedRectange Shape, but i don\'t know how to use t
First, note that the way you were doing it, was not clipping the image. Maybe you did not noticed if the image was too small, or if it had a background of the same color of your canvas. But even while using your beta 4 syntax, you needed to add .clipShape()
.
Back to your question, according to Beta 5 release notes:
Complex overloads for the background(:alignment:) and border(:width:) modifiers are deprecated. Use shapes in a background(:alignment:) or overlay(:alignment:) to draw these instead. (53067530)
So the pattern would be something like this:
.overlay(RoundedRectangle(...).stroke(...).foregroundColor(...))
In your specific case:
Image("mypic").resizable().frame(width: 300, height: 300)
.clipShape(RoundedRectangle(cornerRadius: 30))
.overlay(RoundedRectangle(cornerRadius: 30).stroke(lineWidth: 2).foregroundColor(Color.black))