2

I want to set an image in the titleView of NavigationBar using SwiftUI. We can do this by using UIKit as below:

navigationItem.titleView = UIImageView(image: UIImage(named: "logo"))

This is how we do it in UIKit.

How can I use SwiftUI to achieve this?

halfer
  • 19,824
  • 17
  • 99
  • 186
Sourav Mishra
  • 501
  • 4
  • 21

1 Answers1

4

In SwiftUI 2 you can create a ToolbarItem with the principal placement:

struct ContentView: View {
    var body: some View {
        NavigationView {
            Text("Test")
                .toolbar {
                    ToolbarItem(placement: .principal) {
                        Image(systemName: "ellipsis.circle")
                    }
                }
        }
    }
}
pawello2222
  • 46,897
  • 22
  • 145
  • 209