From the course: iOS 17 Development Essential Training

Unlock this course with a free trial

Join today to access over 22,800 courses taught by industry experts.

Using a slider in SwiftUI

Using a slider in SwiftUI

- Now, let's take a look at making a color picker app. So, we have this icon of a dog from SF symbols, which is a newer icon added for iOS 17. Let's say we want to have some sliders that control the color of the icon. To add a slider, we'll create a new line in our V stack. And then using the library, we'll search for a slider and then press return once it's highlighted. So, you can see that a slider was added on the screen, and now it's asking for a value. This value is a variable that's binding. So, let's actually go up here and create a new value. I'm going to create a variable called 'red' that has a value of 1.0. So, this is going to be a numeric value, and the slider will go from 0 to 1, and it will only control the red value of the dog. So before var, we're going to need the @State attribute. Remember, when we're modifying SwiftUI variables at runtime, we need to call those variables out with the state call out. So…

Contents