Reputation: 895
I am developing app in swiftUI in which every screen has same custom navigation bar with diff titles.
Instead of creating custom navigation view in every screen I want to reuse it.
What will be the best approach to do that?
for now i have done as follow but this works only for single screen
var body: some View {
ZStack {
VStack {
Image("Custom_Navigation_Image")
.resizable()
.frame(height: 135)
.edgesIgnoringSafeArea(.all)
Spacer()
}
}
I want to create custom navigation as below
Thank You for help
Upvotes: 4
Views: 10609
Reputation: 3712
Create a custom view wherein Navigation View embeds the current view:
struct CustomNavBar<Content>: View where Content: View {
let title: String
let content: Content
var body: some View {
NavigationView {
ZStack {
VStack {
Image("12345")
.resizable()
.frame(height: 135)
.edgesIgnoringSafeArea(.all)
Spacer()
}
content
}
.navigationBarTitle(title, displayMode: .inline)
}
}
}
Usage:
var body: some View {
CustomNavBar(title: "Custom Nav", content:
Text("Testing")
)
Upvotes: 3