NEW: My new book Pro SwiftUI is out now – level up your SwiftUI skills today! >>

SOLVED: Fixing an annoying bug...

Forums > SwiftUI

Hi All,

Happy 2022 to you all, I hope 2022 finds you all safe and well!

I'm looking for a little advise please. I have a ScrollView with a couple of VStacks in displaying a scrolling list of items which works great, I wanted to add a bar at the bottom similar to iMessage to add to those items, now placing this inside the ScrollView obviously means it will scroll with the content which isn't what i'm after and after a bit of experimintation I found that placing the code below the scroll view gets me to where I would like to be all baring one thing... whitespace as shown here (colours are just for illistration):

https://ibb.co/pwcy2V5

The code is simply comprised of a VStack with a HStack inside and a TextField and Button, I have not set a frame height but when I do the This is a test code buts right to the top which is what I'd like for all background and elements but for some reason I cannot get the whitespace to disappear, I've even taken off spacing using spacing: 0 everywhere, change/added frame heights still the white space appears, has anybody else experienced this and if so is there a solution?

Many Thanks, Nigel

Edit: I have no idea why the image won't load inline but if you right click and open in a tab it should work, sorry.

1      

Use .overlay(alignment:content:)

ScrollView {
    //your scroll view content
}
.overlay(alignment: .bottom) {
    //the content you want in your bottom bar
}

For example...

.overlay(alignment: .bottom) {
    HStack {
        TextField("Text goes here", text: $text)
            .textFieldStyle(.roundedBorder)
        Button {
            //action
        } label: {
            Image(systemName: "arrow.uturn.up.circle")
                .foregroundColor(.white)
        }
    }
    .padding()
    .background(Color.gray)
}

bottom bar overlay

2      

Thanks roosterboy, you my friend are a genius! I have tried solving this for hours for it to be this simple... am I right thinking that iOS's default spacing got involved in my approach and acted sort of like a safe area?

1      

Hacking with Swift is sponsored by Play

SPONSORED Play is the first native iOS design tool created for designers and engineers. You can install Play for iOS and iPad today and sign up to check out the Beta of our macOS app with SwiftUI code export. We're also hiring engineers!

Click to learn more about Play!

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.