iosswiftswiftuiswiftui-navigationviewlarge-title

SwiftUI: How to align a NavigationBarItem with a large title navigation title?


No matter what I've tried I cannot get this navigation bar item to align with the large title on this View? I have tried padding or placing it in a VStack with a Spacer() but neither push it down. How can I properly align it?

var body: some View {
            NavigationView {
                  //omitted 
                        .navigationTitle("Exertion")
                    }
                    .navigationBarItems(
            trailing:
                    Button(action: {
                        self.isShowingExertionCalendarSheet.toggle()
                    }) {
                        Image(systemName: "calendar")
                              .font(.system(size: 30, weight: .bold))                          
            }
        )   
    }           
}

image


Solution

  • You can't. Because the Navigation Title is dynamic as it can change from small to big on scroll, at least you say otherwise, the UI does not allow you to set up the navigation items aligned vertically in other position other than the expected. That is right below the safe area. Is like giving a leading navigation item hides the back button. This is how Cocoa Touch either via SwiftUI or UIKIt works.