Mango Snippets » #2

SwiftUI: How To Draw Borders With Rounded Rectangles

In SwiftUI, it’s easy to find out there is a .border modifier, and a .cornerRadius modifier. However, those tools can’t create borders with rounded corners. Instead, you can use the .overlay modifier with a RoundedRectangle shape:

Text("DA Tips")
    .padding()
    .overlay(
        RoundedRectangle(cornerRadius: 16)
            .stroke(Color.pink, lineWidth: 2)
    )