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

前端 未结 5 608
一向
一向 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 12:57

    I really liked kontiki's answer but not the length so I wrote:

    import SwiftUI
    
    func strokedRoundedRectangle(
            cornerRadius r: CGFloat,
            lineWidth w: CGFloat = 1,
            color c: Color = .primary
        ) -> some View {
    
        return RoundedRectangle(cornerRadius: r).stroke(lineWidth: w).foregroundColor(c)
    }
    

提交回复
热议问题