Creating a dashed border in SwiftUI
SwiftUI permits you to create sophisticated strokes around the border of a View. The strokes can be customized as much as we want, changing the color, thickness, and the style it's drawn in – either continuous or dashed.
Using this functionality, in this recipe, we'll see how to build a dashed border for an Instagram avatar-like image.
Getting ready
Let's implement a new SwiftUI project called DashedBorderShapeApp
. The recipe requires an image as the base for the avatar – feel free to add your own image or use the one you can find in the GitHub repository in the Resources
folder (https://github.com/PacktPublishing/SwiftUI-Cookbook/blob/master/Resources/Chapter06/recipe2/mountainbike.jpg), courtesy of the Pixabay user David Mark (https://pixabay.com/users/tpsdave-12019). Add the image in the Assets
catalog, calling it mountainbike
.
How to do it...
In this recipe, we'll see how adding a dashed border...