How to remove the default Navigation Bar space in SwiftUI NavigiationView

后端 未结 15 2765
我在风中等你
我在风中等你 2020-11-29 20:00

I am new to SwiftUI (like most people) and trying to figure out how to remove some whitespace above a List that I embedded in a NavigationView

In this image, you can

15条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-29 20:14

    Really loved the idea given by @Vatsal Manot To create a modifier for this.
    Removing isHidden property from his answer, as I don't find it useful as modifier name itself suggests that hide navigation bar.

    // Hide navigation bar.
    public struct NavigationBarHider: ViewModifier {
    
        public func body(content: Content) -> some View {
            content
                .navigationBarTitle("")
                .navigationBarHidden(true)
        }
    }
    
    extension View {
        public func hideNavigationBar() -> some View {
            modifier(NavigationBarHider())
        }
    }
    

提交回复
热议问题