UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

Day 90 Flashzilla: Button extends off screen on lower res devices (e.g. iPhone 6s)

Forums > 100 Days of SwiftUI

Everything looked great in the simulator on the iPhone 11 Pro Max. However, I decided to run it on my own device, an iPhone 6s and found that the Plus button in the top right corner was almost entirely off screen.

I thought that this had something to do with the the way that the VStack{HStack{Button()}} was designed but no, that wasn't it.

Solution was to add a wrap the image in a frame using either UIScreen or a GeometryReader. Credit: Stackoverflow

ZStack {
            Image(decorative: "background")
                .resizable()
                .scaledToFill()
                .edgesIgnoringSafeArea(.all)
                .frame(maxWidth: UIScreen.main.bounds.width, maxHeight: UIScreen.main.bounds.height)

This solved the issue.... According to the post:

You have to limit the frame size of the out-of-bounds Image before it is being picked up by the ZStack to avoid the ZStack to grow and so the Overlay to go out of position.

4      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.