Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get or Set leading spacing of Navigation Title on Large Title Mode - SwiftUI

Tags:

ios

swift

swiftui

I am trying to make sure the Navigation Title (in large title display mode) and various headings/elements below on the page of my iOS app line up, essentially having the same leading padding. The two approaches I can think of are:

  1. Get the value of the default leading padding on the Navigation Title and save that value to specify the leading padding of other elements on the page
  2. Override the default leading spacing between of the Navigation title.

Essentially get/set the spacing represented by the red line in the attached image below. I haven't been successful in either of the options. Does anyone know how to do this?

enter image description here

like image 338
Tyler Pashigian Avatar asked Nov 18 '19 04:11

Tyler Pashigian


1 Answers

I don't know how to get the actual value, but I believe that it's just the default padding amount.

import SwiftUI

struct ContentView: View {
    @State private var text: String = ""
    @State private var searchString = ""
    
    var body: some View {
        NavigationView {
            VStack(alignment: .leading) {
                Text("some text")
                List {
                    Text("Item 1")
                }
                .searchable(text: $searchString)
                Text("some more text")
            }
            .padding(.horizontal)
            .navigationTitle("Title")
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Screenshot of Simulator

like image 75
ProgrammerG Avatar answered Nov 15 '22 05:11

ProgrammerG