Matloob Hasnain
Matloob Hasnain

Reputation: 1037

How to remove back button from navigation bar in whole app using swiftui iOS 13

I am developing an application UI with Swift UI, and I would like to remove Back button from Navigationbar from whole app. is there any way to remove Back Button.

Upvotes: 0

Views: 1082

Answers (3)

Anbu.Karthik
Anbu.Karthik

Reputation: 82759

your code is fine and correct, for example you get the step by step implemntation from SwiftUI Developer portal

import SwiftUI

struct ContentView : View {
    var body: some View {
        VStack {
            Text("Target Color Block")
            Text("Target Color Block")
             Button(action: { 
                 /* handle button action here */ })
            {
         Text("your Button Name")
          .color(.white)
                        .padding(10)
                        .background(Color.blue)
                        .cornerRadius(5)
                        .shadow(radius: 5)
                        .clipShape(RoundedRectangle(cornerRadius: 5))
     }


        }
    }
}

#if DEBUG
struct ContentView_Previews : PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
#endif

Upvotes: 1

Viktor Gardart
Viktor Gardart

Reputation: 4490

It's clearly written in the documentation of SwiftUI of how to use it. Also suggest you to watch the Introducing SwiftUI talk from this year WWDC.

struct ContentView : View {
    var body: some View {
        Button(action: { self.action() }) {
            Text("Button Text")
        }
    }

    private func action() {
        print("Do magic")
    }
}

Upvotes: 0

Fogmeister
Fogmeister

Reputation: 77621

You need to start with some SwiftUI tutorials.

SwiftUI is a complete change from UIKit and so buttons no longer have target/actions.

To add a button you can use...

Button(action: { /* Do something here */ }) {
    Text("Press me")
}

Upvotes: 0

Related Questions