0

I want to use a logo image in the navigation bar's title, instead of plain text. Here some solution for UIKit, but I want to use for SwiftUI also. Any idea will be appreciated.

Screenshot:

enter image description here

ContentView:

struct ContentView: View {
@State private var isShowing = false
var body: some View {
ZStack {
    if isShowing {
        SideMenuView(isShowing: $isShowing)
    }
    
    TabView {
        NavigationView {
            HomeView()
                .navigationBarItems(leading: Button(action: {
                    withAnimation(.spring()) {
                        isShowing.toggle()
                    }
                } , label: {
                    Image(systemName: "list.bullet")
                }))
        }
        .tabItem {
            Image(systemName: "1.circle")
            Text("Page 1")
        }
        NavigationView {
            HomeTwoView()
                .navigationBarItems(leading: Button(action: {
                    withAnimation(.spring()) {
                        isShowing.toggle()
                    }
                } , label: {
                    Image(systemName: "list.bullet")
                }))
        }
        .tabItem {
            Image(systemName: "2.circle")
            Text("Page 2")
        }
    }
    .edgesIgnoringSafeArea(.bottom)
    //.cornerRadius(isShowing ? 20 : 0) //<< disabled due to strange effect
    .offset(x: isShowing ? 300 : 0, y: isShowing ? 44: 0)
    .scaleEffect(isShowing ? 0.8 : 1)

}.onAppear {
    isShowing=false
 }
} 
}

1 Answers1

0

Solution is here. You can add .toolbar {ToolbarItem(placement: .principal) {Image(systemName: "star.fill")} } inside of the NavigationView.

         NavigationView {
                HomeView()
            .toolbar {
            ToolbarItem(placement: .principal) {
            Image(systemName: "star.fill")
         }
        }
          .navigationBarItems(leading: Button(action: {
           withAnimation(.spring()) {
           isShowing.toggle()
            }
             } , label: {
              Image(systemName: "list.bullet")
             }))
            }

Screenshot:

enter image description here