From the course: iOS 14 Development Essential Training
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Increasing reusability in custom views
From the course: iOS 14 Development Essential Training
Increasing reusability in custom views
- [Instructor] Let's say for our ColorSliderView, we also want it to be able to change the color swatch from here in our content view. This will allow us to create blue and green sliders with one line of code each. Let's head over to our ColorSliderView, so I'm hovering over the left side of my screen and full screen, where we can show the navigator view here, So I'm going to ColorSliderView, and I want you to take a minute to think about what it would take to allow us to do what we want. Now, if you're new to programming it might be a difficult puzzle to solve. What we need to do is create another variable so that whenever we create a ColorSliderView, we need to send in this value as well. So below binding var, type var, color, colon the data type for this is going to be a color. Remember, we did the exact same thing in our color swatch and we don't need to use the @Binding or at state color. Now, if you want to, you…
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.
Contents
-
-
-
-
-
-
Getting text input with SwiftUI4m 45s
-
Using a slider in SwiftUI5m 26s
-
Creating a slider with a color swatch2m 38s
-
Making a custom SwiftUI view5m 22s
-
Creating a reusable slider component4m 54s
-
Increasing reusability in custom views3m 13s
-
Challenge: Build a color picker app1m 19s
-
Solution: Build a color picker app1m 17s
-
-
-