swiftuiuinavigationitemnavigationitem

Adding Back icon and "Back" text within a UINavigationItem button in SwiftUI


I have a button that i want it have the < back icon and also back text to it . This is what i did:

Text("\(Image(systemName: "chevron.left"))Back")

I am getting this error:

Instance method 'appendInterpolation' requires that 'Image' conform to '_FormatSpecifiable'

I tried fixing it as :

Text("\(Image(systemName: "chevron.left"))Back" as String)

But it does not work. How can i fix it .


Solution

  • You can create a back button like this:

    Button(action: {
        
    }, label: {
        HStack(spacing: 4) {
            Image(systemName: "arrow.left")
            Text("Back")
        }
    })
    .accentColor(.blue)
    

    However, I would note that if you are using a NavigationView and are segueing with a NavigationLink, the back button will automatically be there and you do not need to recreate it.