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

SOLVED: Large gap in UI

Forums > SwiftUI

Hi, I have searched a number of topics on this and the suggested solutions do not seem to work. Hoping someone here can help.

In the UI there is a large gap above the "Banner" image at the top. I'm assuming this is the space for the Navigation Bar Title but have hidden Navigation Bar.

Here is the code:

struct WelcomeView: View {
    @State private var angle = 0.0

    var body: some View {
        NavigationView {
            VStack {
                GeometryReader { geo in
                        .aspectRatio(contentMode: .fit)
                        .frame(width: geo.size.width * 1.0)
                        .frame(width: geo.size.width, height: geo.size.height)

                ZStack {

                    Button (action: {
                        self.angle += Double.random(in: 3600..<3960)
                    }) {
                        GeometryReader { geo in
                                .frame(width: geo.size.width * 0.6)
                                .frame(width: geo.size.width, height: geo.size.height)
                                .animation(.timingCurve(0, 0.8, 0.2, 1, duration: 10), value: angle)

                        .shadow(radius: 5)

                    Image(systemName: "arrowtriangle.up.fill")
                        .font(.system(size: 30))
                        .padding(.bottom, 40)

                Text("Take the quiz and find out which colour best matches your FPL style")

                NavigationLink(destination: QuizView(), label: {
                   Text ("Start Quiz")

Please does anyone have any suggestions on how to move the image to the top of the screen? Thanks in advance


Is this close to what you are after?

let yOffset: CGFloat = 50

    .aspectRatio(contentMode: .fit)
    .frame(width: geo.size.width * 0.8)
    .frame(width: geo.size.width, height: geo.size.height)
.offset(X: 0, y: yOffset)


Thanks @Greenamberred, aplying that offset to the banner image helps me to pull it to the top of the screen.

I'm not sure if this was what I was looking for in a solution though and I am new to this so please excuse if I worded incorrectly.

I essentially have 4 elements to this welcome view;

  • Banner image (top)
  • Spinning wheel image (about half the screen but aligned just north of centre)
  • Some text (equally spaced between wheel and start quiz)
  • Start Quiz button (bottom)

My intention is to control the layout of these using frames, padding and spacers. But the UI is squishing them down with this white space at the top.

Your solution pulls the banner image into the white space using the offset. However, the remaining items remained squished towards the bottom of the UI.

My thinking is I could use other yOffset values for these elements too but then I am artificially pulling them up or down the UI and not sure this would scale well between devices. I could be wrong though.

Does that make sense? As I said, I am still learning and what I am aspiring to won't work but if I had the same elements laid out in a non Navigation View, they would layout evenly without this white space no?


I'm only on mobile but maybe VStack(spacing: 0)? Or edgesIgnoringSafeArea(.top)?


I have found the solution and it was much more simpler than expected.

Went back to watch one of Paul's videos on Navigation views and found that my navigationBarHidden modifier was at the wrong level, moving it to modifier what is in the Navigation View resolved the issue


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!

Reply to this topic…

You need to create an account or log in to reply.

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.