admin管理员组

文章数量:1123869

I'm trying to customize the toolbar colors in a NavigationSplitView, specifically:

  • Set a color for the sidebar's toolbar (which contains the toggle sidebar button)
  • Set a different color for the detail view's toolbar (which contains the star button)

Currently, when I use .toolbarBackground(), the sidebar's color settings seem to override the detail view's settings. For example:

NavigationSplitView {
    List {
        // Sidebar content
    }
    .toolbarBackground(.black) // Changes BOTH sidebar and detail toolbar
} detail: {
    // Detail content
    .toolbarBackground(.blue)  // Ignored
}

Result: Black Toolbar Only (I want to maintain split with black and blue toolbars)

I've tried playing with .toolbarVisibility(.hidden) on the sidebar and .toolbarVisibility(.visible) on the detail view, but same effect. It only ever follows the sidebar modifiers.

How can I set distinct toolbar colors for each side of the SplitView?

本文标签: swiftSwiftUI NavigationSplitView Distinct Toolbar ColorsStack Overflow