From the course: iOS 17 Development Essential Training
Unlock this course with a free trial
Join today to access over 24,800 courses taught by industry experts.
Adding custom SwiftUI attributes
From the course: iOS 17 Development Essential Training
Adding custom SwiftUI attributes
- [Instructor] Now in the color slider view, let's fix our preview. So I'll select those three lines at the bottom that have the preview and are commented out, and then press command / on the keyboard to uncomment them. So the problem here is that we're missing the color value argument. So inside of the parentheses type colorValue, and then just use code hinting to complete it. And then what we're going to do here is pass in a value using the .constant constructor. And this creates a binding with an immutable value. So you often use this in previews to be able to give it a solid value without having to create binding or state variables. So all we have to do is type .constant, and then the parentheses just give a default value. Let's go with 0.5. And there we go. The slider is at 50%. So if you want to change that to something else, like 0.75, you can see that the canvas updates. So change it to a value that you'd like.…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.