EN VI

Swiftui - How can I fix Text("").toolbar causing dead space at the top of my content space?

2024-03-15 14:30:04
Swiftui - How can I fix Text("").toolbar causing dead space at the top of my content space

I have a Toolbar View that is causing an issue. The call to Text( "" ).toolbar is placing adding dead space at the top of the content window space. I have tried substituting Text() with other items (form, scrollingView etc.) but they are not the GUI I want. Gosh I don't want the Text Object but that seams required for .toolbar to work. It looks like this:

enter image description here

The toolbar is supposed to show up in the titlebar of the window, which it does.

I can't figure out what I've done wrong here. Uncommenting the .borders show a tight wrapper around those objects. Adding ABC as the text shows the dead space at the top with ABC centered on the screen. This of course is a simplified version of my code.

struct ToolbarView: View {
    var body: some View {
        HStack {
            Text( "" )
              .toolbar
            {
                Button( "Hi!", systemImage: "rectangle" )
            }   // End of toolbar
            .border(Color.purple)   
        }   // End of Stack
    }
}

Which I call like this:

struct ContentView: View {  
    var body: some View {
        ToolbarView( )
        GeometryReader { geometry in
            HStack {
                Group {
                    Text( "For Content" )
                }
                .frame( maxWidth: .infinity, maxHeight: .infinity ) // required to fill space
                .background(Color.white)
//              .border(Color.blue, width: 4)

                Group {
                    Text( "My panel" )
                }
                .frame( width: 300 )
                .background( .black )
                .animation(.easeInOut( duration: 0.5 )) // TODO: Update this
                .transition(.move(edge: .trailing))
//              .border(Color.pink, width: 4)
            }

        }
    }
}

struct MyCADApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView( )
                .frame( minWidth: 1000, minHeight: 600 )
        }
    }
}

Solution:

try replacing your Text( "" ) with VStack{}, works for me.

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login