I've added a .toolbar to the top level of a NavigationView that will eventually be used to select items in a list without using swipe gestures (up button, down button, etc.). I also have a .navigationBar going on, to access other views for Account and Settings.
For the most part it's looking really good, but when I follow a NavigationLink (in .navigationBarItems) within NavigationView, and then use the built-in back navigation, my .toolbar disappears from the top level.
Am …
通常,出于可访问性原因,我喜欢坚持使用默认颜色选项,但我有一个特定的用例,我无法更改单个 .toolbar ToolbarItem 颜色。
我可以通过使用代码段顶部注释掉的代码来覆盖所有ToolbarItem 颜色,但我想为单个图标着色。
import SwiftUI
struct ContentView: View {
// init() {
// UIBarButtonItem.appearance(whenContainedInInstancesOf: [UIToolbar.self]).tintColor = .systemRed
// }
var body: some View {
NavigationView {
Text("Hello, world!")
.toolbar {
// To be colored RED
ToolbarItem(placement: .bottomBar) {
Button(action: {}, label: {Label("Icon One", systemImage: "stop.fill")})
}
// To be colored BLACK
ToolbarItem(placement: .bottomBar) {
Button(action: {}, label: {Label("Icon Two", systemImage: "play.fill")})
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: …Run Code Online (Sandbox Code Playgroud)