Sourav Mishra
Sourav Mishra

Reputation: 531

How to set image for NavigationBar title using SwiftUI?

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?

Upvotes: 2

Views: 1554

Answers (1)

pawello2222
pawello2222

Reputation: 54426

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")
                    }
                }
        }
    }
}

Upvotes: 7

Related Questions