Group Group Group Group Group Group Group Group Group

Chapter 7: General question about background

I’m about to finish chapter 7 and my Bullseye app is working great. I’ve been fiddling around with some code to get a better idea of how things work and I’m confused about calling background(). The developer documentation didn’t help me.

For the vertical stack we call this:

.background(Image(“Background”))

That makes the background image completely fill the entire screen, including around the notch in the simulated iPhone 11.

However, I’m confused about the result when I change the line to read this instead:

.background(Color.blue)

Why does the background suddenly not fill the entire screen?

Looks like it’s more of an AutoLayout constraint issue. Seems like when the image background is large enough, it will automatically fit itself and expands the UIImageView, however when you set it to background color to blue, now it uses its set width & height.

Can you try playing around with the constraint layout of the UIImageView?

Screen Shot 2020-04-03 at 23.48.28

I’d know how to do that with UIKit, but not with SwitftUI at this point in the lessons. Don’t worry about it, I was just curious why it was behaving this way. Thanks for the info.

Try these modifiers
.frame(maxWidth: .infinity, maxHeight: .infinity) &
.edgesIgnoringSafeArea(.all)

1 Like

That does work! One of the buttons gets a little pushed off of the screen but it does do what I asked. Thanks for the tip.