Updated for Xcode 14.2
Any SwiftUI view can have its corners rounded using the cornerRadius()
modifier. This takes a simple value in points that controls how pronounced the rounding should be.
So, you can create a text view with 15-point rounded corners like this:
Text("Round Me")
.padding()
.background(.red)
.cornerRadius(15)
Download this as an Xcode project
You can automatically round the shortest edge fully by using the clipShape()
modifier with a Capsule
, like this:
Text("Round Me")
.padding()
.background(.red)
.clipShape(Capsule())
Download this as an Xcode project
SPONSORED From March 20th to 26th, you can join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer!
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.