小编Sun*_*rts的帖子

SwiftUI .toolbar disappears after following NavigationLink and coming back

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 …

swiftui swiftui-navigationlink swiftui-navigationview

15
推荐指数
1
解决办法
1157
查看次数

SwiftUI:为 .toolbar ToolbarItem 设置单独的颜色?

通常,出于可访问性原因,我喜欢坚持使用默认颜色选项,但我有一个特定的用例,我无法更改单个 .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)

swiftui

5
推荐指数
2
解决办法
2007
查看次数