Home > OS >  SwiftUI - How to add an Image beside the title in the navigationbar?
SwiftUI - How to add an Image beside the title in the navigationbar?

Time:08-12

How do I add an image to in the corner of the navigationbar, keeping the title in the center?

something like this -

enter image description here

CodePudding user response:

here is the code:

struct ContentView: View {
var body: some View {
            
    NavigationView{
        
        Text("Hello")

        .navigationBarTitleDisplayMode(.inline)
                .toolbar {
                    ToolbarItem(placement: .principal) {
                            Text("Title")
                                .font(.title)
                    }
                    
                    ToolbarItem(placement: .navigationBarTrailing) {
                            Image(Constants.logoImage).resizable()
                                .scaledToFit()
                                .frame(width: 100, height: 50, alignment: .trailing)
                        }
                    }
    }
}
}
  • Related