Search code examples
swiftuinavigationview

Remove NavigationView close icon SwiftUI


This is the icon How do I remove this icon?

I am using very simple code; just navigation view


Solution

  • As mentioned in the comments by @Nirav D, this button is used to toggle the sidebar visibility.

    iOS 16 & above

    In iOS 16, Apple gave Navigation a big refresh:

    1. Introducing NavigationStack(which is probably what you want), it is used to present a view allowing the user to navigate using NavigationLink as you would on an iPhone.
    2. Introducing NavigationSplitView(which is what you’re seing in the simulator right now), it is used to present a menu (sidebar) that can present detail views. You can have up to 3 columns.
    3. Deprecating NavigationView, from now on you have to use the above containers as NavigationView will be obsoleted in a future iOS release.

    iOS 15 & below

    In versions earlier than 16, you have to use NavigationView. NavigationView accepts navigationViewStyle, the default style on iPhone is StackNavigationViewStyle where the content is presented in one column. However, on iPad in order to maximise the use of screen estate, SwiftUI sets the default style to ColumnNavigationViewStyle that presents the content in columns (Master -> Detail…).

    • If you mean to use a single column: you must use either NavigationStack or NaigationView with .navigationViewStyle(.stack);

    • If you have to use multiple columns & still hide the button: use .navigationBarHidden(true) on the sidebar view, or .toolbar(.hidden, for: .navigationBar) for iOS 16+.

    For more info, check: Navigation & The SwiftUI cookbook for navigation