Custom back button for NavigationView's navigation bar in SwiftUI

后端 未结 9 719
隐瞒了意图╮
隐瞒了意图╮ 2020-11-29 23:57

I want to add a custom navigation button that will look somewhat like this:

Now, I\'ve written a custom BackButton view for this. When applying

9条回答
  •  既然无缘
    2020-11-30 00:39

    Swiping is not disabled this way.

    Works for me. XCode 11.3.1

    Put this in your root View

    init() {
        UINavigationBar.appearance().isUserInteractionEnabled = false
        UINavigationBar.appearance().backgroundColor = .clear
        UINavigationBar.appearance().barTintColor = .clear
        UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
        UINavigationBar.appearance().shadowImage = UIImage()
        UINavigationBar.appearance().tintColor = .clear
    }
    

    And this in your child View

    @Environment(\.presentationMode) var presentationMode: Binding
    
    Button(action: {self.presentationMode.wrappedValue.dismiss()}) {
        Image(systemName: "gobackward")
    }
    

提交回复
热议问题