SwiftUI for Absolute Beginners by Jayant Varma

SwiftUI for Absolute Beginners by Jayant Varma

Author:Jayant Varma
Language: eng
Format: mobi
ISBN: 9781484255162
Publisher: Apress
Published: 2020-11-08T12:08:32.127879+00:00


Figure 5-7 Menu-based option from the Editor menu

Figure 5-8 Context menu with the Command button pressed

Gradients

We saw that we can use gradient backgrounds by simply using a LinearGradient and pass it to the background modifier. In a similar fashion, we can also assign a LinearGradient to a stroke and/or a fill. A stroke is the border used on a shape or text, and instead of a plain boring unicolor border stroke, we can add a thicker border with a gradient that makes it pop out.

We can create a circle with Circle(); this positions a large black circle in the middle of the screen. This is basically filled with the default color, black. Next, we can add a modifier to this, a stroke with a thickness of 5 pixels:

Circle()

.stroke(linewidth: 5)

We can see that now the circle has a border with a thickness of 5 pixels but not filled. If we change this to a larger number like 25, we get a thick solid border that can benefit from a gradient color on it:

Circle()

.stroke(

LinearGradient(gradient: Gradient(colors:[.red, .blue]),

startPoint: .top,

endPoint: .bottom),

linewidth: 25)

This will create a gradient circle for us of 25 pixel thickness as can be seen in Figure 5-9.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.