From the course: Complete Guide to SwiftUI

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Basic backgrounds

Basic backgrounds

- [Instructor] We've looked at foregrounds. Now let's look at backgrounds. Until we set a nice color for the foreground, we used a background modifier to help us see the title in the header view. You could use background modifiers in any view, replacing the transparent background with a color. Now we have several of the same choice for colors we had for foregrounds plus a few more. Commonly, you'll place backgrounds on stacks or views, giving a background to all the stacks or views. For example, I'm going to go into order view here, and I could put this VStack, and I'm going to go up here. I'm going to collapse the VStack for a sec, and I'm going to put underneath this VStack, a background. And then inside the background, I'm going to put a color, and we'll use surf for this. And now the whole background is that color. If I had done this with padding afterwards, notice what happens. The padding pushes the background inward a little bit, and you've got a margin that doesn't have the…

Contents