From the course: iOS 14 Development Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Making a custom SwiftUI view

Making a custom SwiftUI view

From the course: iOS 14 Development Essential Training

Start my 1-month free trial

Making a custom SwiftUI view

- [Instructor] At this point in our app we've only used the built-in SwiftUI components HStack, VStack, Circle, Slider, et cetera. But you can actually create your own UI components that gives you the benefit of being able to reuse them and to make your code more readable. Let's take a look at how that might work by making this circle here into its own SwiftUI view. Press Command + N to create a new file and go to iOS user interface, SwiftUI View, and hit Next. Now save this file as ColorSwatch and then hit Return to create the file. So we have this ColorSwatch right here and we have the text that says "Hello, World." So, now we can actually go back and our content view and let's say, I go in my HStack here, I can create a ColorSwatch just like that. You type ColorSwatch just as you typed it in your file name, and it adds that to your view. So if I hit resume right here, it's not going to look very pretty but you'll see…

Contents