Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View going under Status Bar in SwiftUI

How can I stop a view in SwiftUI going under the Status Bar when using a ScrollView? I already tried to place a view directly under the status bar, but it didn't have an effect.

I didn't use .edgesIgnoringSafeArea anywhere.

My Code:

ScrollView {
    HStack {
        Spacer()
        Text("ScrollMe")
            .padding()
    }
}

Screenshot:

Example

like image 588
J-- Avatar asked Oct 12 '25 15:10

J--


1 Answers

This is expected behavior for a ScrollView to scroll off the screen into the safe area insets.

If you really want to avoid this behavior, you need some other interim view with a non-zero height that will sit below the safe area. For example, modifying your code:

struct ContentView: View {
    var body: some View {
        VStack {
            Spacer().frame(height: 1)
            ScrollView {
                HStack {
                    Spacer()
                    Text("ScrollMe")
                        .padding()
                }
            }
        }
    }
}
like image 185
jnpdx Avatar answered Oct 14 '25 14:10

jnpdx