Add a border with cornerRadius to an Image in SwiftUI Xcode beta 5

前端 未结 5 603
一向
一向 2021-02-05 12:08

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

5条回答
  •  南方客
    南方客 (楼主)
    2021-02-05 13:10

    Write a rounded text view which is same with Image View

    struct RoundedTextView: View {
        var body: some View {
            Text("Rounded Text View")
                .frame(width: 200, height: 200, alignment: .center)
                .foregroundColor(.white)
                .background(Color.blue)
                .cornerRadius(16)
                .overlay(
                    RoundedRectangle(cornerRadius: 16).stroke(Color.yellow, lineWidth: 8)
                )
        }
    }
    

    Preview like this image:

提交回复
热议问题