Member-only story

Displaying Borders in SwiftUI

Displaying borders around views in SwiftUI is easy, and this post shows how to draw borders that are simple, rounded, or have another shape.

Gabriel Theodoropoulos
5 min readNov 26, 2021
Photo by Bermix Studio on Unsplash

SwiftUI makes it quite easy to create beautiful user interfaces. That fact becomes even bolder when it comes to apply simple styling to views, as many times a single line of code is enough to do the job. Drawing borders confirms that statement, as we can achieve nice results with almost no effort at all. This post demonstrates how to display simple borders around views, as well as how to create more complicated and configurable borders.

Displaying a simple border around a view is just a matter of calling a view modifier. The following code illustrates that by adding a border around a text view. Note that specifying the desired color for the border is mandatory:

--

--

Gabriel Theodoropoulos
Gabriel Theodoropoulos

Written by Gabriel Theodoropoulos

An iOS & macOS app maker writing code in Swift. Author of countless programming tutorials. Content creator. https://serialcoder.dev

No responses yet