SwiftUI Custom navigation bar with list
This is what I have achieved using swiftUI and a bit of UINavigationView, I believe those modifiers will be implemented to swiftUI after beta.
I achieved this by tweaking max's idea about the UINavigationBar's appearance. How can the background or the color in the navigation bar be changed?
Aside from that, I just throw a toggle to the NavigationBar title's view
var body: some View {
VStack {
if displayImg {
Image("dontstarve")
.resizable()
.aspectRatio(contentMode: .fill)
.edgesIgnoringSafeArea(.all)
} else {
Image(systemName: "play")
}
}
.navigationBarTitle(Text("Adjustment"), displayMode: .inline)
.navigationBarItems(trailing:
HStack {
Toggle(isOn: $displayImg) {
Text("\(self.displayImg ? "on" : "off")")
.foregroundColor(Color.white)
}
})
}
Below are the only code that isn't SwiftUI. Which I just throw all of them in init():
init() {
UINavigationBar.appearance().tintColor = .systemGray6
UINavigationBar.appearance().barTintColor = .systemTeal
UINavigationBar.appearance().titleTextAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white, NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 25)]
}
And yes, remember to set the navigation bar title mode to inline:
.navigationBarTitle(Text("Home"), displayMode: .inline)
You can do something like this to make it like previous iOS 13 Navigation Bar, which then removes the large title and places it on the bar in the middle all the time:
.navigationBarTitle(Text("Landmark"), displayMode: .inline)