Round Specific Corners SwiftUI

前端 未结 4 1687
不思量自难忘°
不思量自难忘° 2020-12-02 09:12

I know you can use .cornerRadius() to round all the corners of a swiftUI view but is there a way to round only specific corners such as the top?

4条回答
  •  北海茫月
    2020-12-02 09:28

    Another option (maybe better) is actually to step back to UIKIt for this. Eg:

    struct ButtonBackgroundShape: Shape {
    
        var cornerRadius: CGFloat
        var style: RoundedCornerStyle
    
        func path(in rect: CGRect) -> Path {
            let path = UIBezierPath(roundedRect: rect, byRoundingCorners: [.topLeft, .topRight], cornerRadii: CGSize(width: cornerRadius, height: cornerRadius))
            return Path(path.cgPath)
        }
    }
    

提交回复
热议问题