Your First iOS & SwiftUI App: Polishing the App

Mar 1 2022 · Swift 5.5, iOS 15, Xcode 13

Part 2: Swift Coding Challenges

21. Environment Property Wrapper

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 20. Challenge: Draw the Rings Next episode: 22. Challenge: Center the Slider

Notes: 21. Environment Property Wrapper

EnvironmentValues in the official Apple Documentation

Transcript: 21. Environment Property Wrapper

Bullseye is looking really awesome at this point, except for one thing that’s really bugging me.

The slider isn’t centered!

And I don’t know about you, but that triggers my OCD in a major way, so we’ve gotta fix this.

Here’s one easy way to fix this. It turns out whenever you put a view inside a ZStack, it centers the view within that ZStack.

So, we can simply move the SliderView to the bottom of the ContentView’s ZStack, so it’s on the very top.

And then, we need to add some padding between the InstructionView and the HitMeButton, to make up for the fact that the slider isn’t there anymore. A bottom padding of about 100 will do.

You should know enough about SwiftUI that you can do this on your own. So pause the video and give it a shot. Good luck!

Move SliderView down two with Option+Cmd+].

Add this to the bottom of the InstuctionView:

.padding(.bottom, 100)