Filling a border with an image
We know that filling a border with color is pretty easy, but what about an image?
It turns out that, like gradients in the Rendering a border with a gradient recipe, using an image for styling a stroke is straightforward.
Getting ready
We are going to use an image to fill the border, and you can either use JesterBackground
, provided for you in the GitHub repo in the Resources
folder (https://github.com/PacktPublishing/SwiftUI-Cookbook/blob/master/Resources/Chapter06/recipe10/JesterBackground.png), or add one of your choice.
Create a SwiftUI project called ImageBorderApp
and add the image to the Assets
folder.
How to do it...
In this recipe, we are going to render a simple Circle
and add an image in the strokeBorder()
modifier:
- Let's add
Circle
inside thebody
of theContentView
struct and make it central on the screen with some padding:struct ContentView: View { var body: some View { ...