From the course: Complete Guide to SwiftUI
ContentView previews
From the course: Complete Guide to SwiftUI
ContentView previews
- [Instructor] Now that you know a little about modifiers, your code is not the only place you can use modifiers. You can also use modifiers to make changes to your canvas device. So let's give ourselves some room here. I'm going to scoot this over a bit 'cause we don't need all that space for the device. And that looks pretty good the way it is, but you can make it a little bigger if you want, or a little smaller. Yeah, I'll just let it fit. And then if you go down the code a bit, you'll find there's another struct here called ContentView_Previews. This drives the preview you see on the right, launching this view into the preview pane. As we code views, you'll make sure this code has proper values to launch the preview, including test values. You can also test with modifiers. One easy modifier to add to it is for dark mode. So if you go after ContentView here, I'm just press Return and I'm going to just put in here colorScheme. And you got your choice of dark or light or all cases. I'm going to just go for the dark here. And it does something weird, okay? Many machines you'll find the text disappears if you do this, but the background remains white. This is a bug in SwiftUI, but you can get around it by adding another modifier and that's the background modifier. So actually put in here background(Color.black) and there it is up there. Now you can see that we've got our color here and that these turned white, but they were white on white 'cause, for some reason, previews just does not want to make a black background. So that's one way of doing it. Now I'm going to go ahead and delete that 'cause there's an easier and better way to check on how to use things over here in the previews. And that's the buttons down over here. First one we'll look at is these two switches here that says Device Settings. If you go in there, you can actually just turn on a color scheme and there you go. In one click, you can check to see if it's okay or not. And then click it off and see it again. You also got for orientation. So if I click on this for the orientation, you can see I can change the landscape left or landscape right, and see what it looks like in that way. I'm going to turn that back off. I'll put it on left and off again. And you get the same thing with dynamic type here as well. Let's turn that on. And you can see on the top there, as I turn this, it gets bigger and smaller. All right, and I'll turn that off. Now if you want to look at a whole bunch at the same time, there's this button next to it, okay, called the Variants. And I'm going to go into here and do orientation variants, and it shows me all of the variants all at the same time. So I got both the landscape left, right, and portrait. So I get some preview of what I'm going to be doing. And this is, of course, still responsive to the Device Settings over here so I can check all of them, for example, in dark mode. Okay, now that's the basics of using the SwiftUI environment. I'm going to head back to just our standard mode here. And from here, we're going to start building our pizza app with all the current features of SwiftUI.
Download courses and learn on the go
Watch courses on your mobile device without an internet connection. Download courses using your iOS or Android LinkedIn Learning app.
Contents
-
-
(Locked)
Embed a stack view6m 29s
-
(Locked)
Text views3m 41s
-
(Locked)
Image views with SF Symbols5m 22s
-
(Locked)
Iteration with ForEach5m 13s
-
(Locked)
Images and assets4m 56s
-
(Locked)
Labels2m 22s
-
Add view2m 49s
-
(Locked)
Challenge: Add views26s
-
(Locked)
Solution: Add views2m 33s
-
(Locked)
Extract subviews8m 4s
-
(Locked)
Subviews with parameters6m 37s
-
(Locked)
Challenge: Ratings view44s
-
(Locked)
Solution: Ratings view3m 55s
-
(Locked)
-
-
(Locked)
Presenting views2m 19s
-
(Locked)
Space modifiers2m 54s
-
(Locked)
Shape modifiers3m 54s
-
(Locked)
Text modifiers8m
-
(Locked)
Color modifiers6m 4s
-
(Locked)
Basic backgrounds8m 29s
-
(Locked)
Materials and shadows7m 17s
-
Scale modifiers4m 42s
-
(Locked)
Size modifiers5m 25s
-
(Locked)
Clean up joined views6m 9s
-
(Locked)
Challenge: Clean up OrderView1m 28s
-
(Locked)
Solution: Clean up OrderView8m 36s
-
(Locked)
-
-
(Locked)
MVC vs. MVVM4m 19s
-
(Locked)
State variables and buttons3m 57s
-
(Locked)
Challenge: Add a button45s
-
(Locked)
Solution: Add a button3m 50s
-
(Locked)
Use Binding variables10m 10s
-
(Locked)
The Identifiable protocol5m 13s
-
(Locked)
Add a model to root views6m 47s
-
Populating collections with List4m 45s
-
(Locked)
Selection and binding variables6m 29s
-
(Locked)
-
-
(Locked)
Toggles and steppers6m 8s
-
(Locked)
Pickers6m 10s
-
(Locked)
Moving data in pickers5m 54s
-
Text input7m 1s
-
(Locked)
Lazy grids6m 37s
-
(Locked)
Tap gestures3m 1s
-
(Locked)
Reacting to changes5m 59s
-
(Locked)
Challenge: Favorites grid1m 46s
-
(Locked)
Solution: Favorites grid8m 55s
-
(Locked)
Challenge: Add a grid view to the app40s
-
(Locked)
Solution: Add a grid view to the app6m 10s
-
(Locked)
-
-
(Locked)
SF Symbols app3m 59s
-
(Locked)
SF Symbols variants4m 53s
-
(Locked)
SF Symbols in color: Monochrome and multicolor4m 2s
-
(Locked)
SF Symbols in color: Palette and hierarchical3m 28s
-
(Locked)
SF Symbols variable color3m 42s
-
(Locked)
SF Symbols animation, part 13m 44s
-
(Locked)
SF Symbols animation, part 23m 47s
-
(Locked)
Replace effects3m 56s
-
(Locked)
Challenge: Variants, modes, and effects55s
-
(Locked)
Solution: Variants, modes, and effects7m 4s
-
(Locked)
-
-
(Locked)
Navigation links3m 57s
-
(Locked)
Stack navigation in lists5m 58s
-
(Locked)
Deeper navigation stacks4m 47s
-
(Locked)
Create navigation paths4m 1s
-
(Locked)
Use navigation paths6m 7s
-
(Locked)
More navigation destinations4m 26s
-
Toolbars4m 15s
-
(Locked)
Navigation title5m 22s
-
(Locked)
List interaction2m 53s
-
(Locked)
-
-
(Locked)
Extensions5m 14s
-
(Locked)
Custom modifiers3m 53s
-
(Locked)
More modifiers2m 33s
-
(Locked)
Modifiers with parameters5m 13s
-
(Locked)
Shapes6m 11s
-
(Locked)
Modifiers with added views5m 19s
-
(Locked)
ViewBuilder3m
-
(Locked)
Conditional ViewBuilder3m 40s
-
(Locked)
Challenge: Make Home a back button29s
-
(Locked)
Solution: Make Home a back button5m 36s
-
(Locked)
-
-
(Locked)
Introducing the capstone project2m 55s
-
(Locked)
The model schema2m 10s
-
(Locked)
Add model to project1m 47s
-
(Locked)
The model implementation5m 2s
-
A dual key model6m 12s
-
(Locked)
Styles4m 38s
-
(Locked)
Code custom controls4m 38s
-
(Locked)
Ingredients view4m 36s
-
(Locked)
Add navigation3m 31s
-
(Locked)
Recipe view5m 33s
-
(Locked)
Add and edit recipes5m 8s
-
(Locked)
Testing6m 54s
-
(Locked)