Avatar ·

How to round only certain corners of a View in SwiftUI?

Hello everyone! I'm a beginner in SwiftUI and ran into a problem: I need to round only the top two corners of a rectangular View, while keeping the bottom corners straight. In regular UIKit I used UIBezierPath and CAShapeLayer, but in SwiftUI there doesn't seem to be a direct modifier for selective rounding.

\n\n

I tried using .cornerRadius(20), but it rounds all four corners. I also read about .clipShape(RoundedRectangle(cornerRadius: 20)), but that doesn't solve the problem either — it rounds all corners.

\n\n

Here's an example of my code:

\n\n
struct ContentView: View {\n    var body: some View {\n        VStack {\n            Text("Hello, world!")\n                .padding()\n                .background(Color.blue)\n                .cornerRad