Friday, August 14, 2026
HomeiOS Developmentios - How one can present App Brand in All Navigation Bar...

ios – How one can present App Brand in All Navigation Bar in SwiftUI App

[ad_1]

I’ve an app, which shows brand within the heart of the NavigationBar in SwiftUI. The app is utilizing NavigationStack in iOS 16. Right here is the implementation.

struct DetailView: View {
    var physique: some View {
        Textual content("Element View")
    }
}

struct ContentView: View {
    var physique: some View {
        NavigationStack {
            VStack {
                NavigationLink("Element", worth: "Element")
                    .toolbar {
                        ToolbarItem(placement: .principal) {
                            Picture(systemName: "coronary heart.fill")
                                .foregroundColor(.pink)
                        }
                    }
            }.navigationDestination(for: String.self) { stringValue in
                DetailView()
            }
        }
    }
}

This shows the center brand within the heart of the NavigationBar however as quickly as I am going to DetailView, the center brand is gone. How can I ensure that the center brand is on the market on app the navigation bars within the app.

UPDATE: I can remedy this drawback by making a customized NavigationContainerView as proven beneath:

struct CustomNavigationView<Header: View, Content material: View>: View {
    
    let header: Header
    let content material: () -> Content material
    
    init(header: Header, content material: @escaping () -> Content material) {
        self.header = header
        self.content material = content material
    }
    
    var physique: some View {
        VStack {
            
            Picture(systemName: "coronary heart.fill")
                .foregroundColor(.pink)
            
            NavigationStack {
                content material()
                    .navigationDestination(for: String.self) { stringValue in
                        Textual content("Element")
                    }
            }
            
                .toolbar {
                    ToolbarItem(placement: .principal) {
                        header
                    }
                }
        }
    }
}

However this creates a small hole between the NavigationBar and the again button as proven beneath:

enter image description here

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments