Skip to main content
+ ToolbarContent extension
Source Link
Benzy Neez
  • 29.6k
  • 3
  • 22
  • 64

Try applying .sharedBackgroundVisibility(.hidden) to the ToolbarItem:

.toolbar {
    ToolbarItem(placement: .topBarTrailing) {
        Button {
        } label: {
            Image(systemName: "plus")
        }
    }
    .sharedBackgroundVisibility(.hidden) // 👈 here
}

Screenshot


EDIT As you pointed out in a comment, the modifier .sharedBackgroundVisibility is only available for iOS 26. If you are supporting an earlier build target, the modifier needs to be applied conditionally. This conditional code can be encapsulated as an extension of ToolbarContent:

extension ToolbarContent {

    @ToolbarContentBuilder
    func hideSharedBackgroundIfAvailable() -> some ToolbarContent {
        if #available(iOS 26.0, *) {
            sharedBackgroundVisibility(.hidden)
        } else {
            self
        }
    }
}

Now the function hideSharedBackgroundIfAvailable can be used in place of the modifier sharedBackgroundVisibility in the code above:

ToolbarItem(placement: .topBarTrailing) {
    // content as before
}
.hideSharedBackgroundIfAvailable() // 👈 here

I would expect this to compile with all build targets from iOS 14.0 onwards.

Try applying .sharedBackgroundVisibility(.hidden) to the ToolbarItem:

.toolbar {
    ToolbarItem(placement: .topBarTrailing) {
        Button {
        } label: {
            Image(systemName: "plus")
        }
    }
    .sharedBackgroundVisibility(.hidden) // 👈 here
}

Screenshot

Try applying .sharedBackgroundVisibility(.hidden) to the ToolbarItem:

.toolbar {
    ToolbarItem(placement: .topBarTrailing) {
        Button {
        } label: {
            Image(systemName: "plus")
        }
    }
    .sharedBackgroundVisibility(.hidden) // 👈 here
}

Screenshot


EDIT As you pointed out in a comment, the modifier .sharedBackgroundVisibility is only available for iOS 26. If you are supporting an earlier build target, the modifier needs to be applied conditionally. This conditional code can be encapsulated as an extension of ToolbarContent:

extension ToolbarContent {

    @ToolbarContentBuilder
    func hideSharedBackgroundIfAvailable() -> some ToolbarContent {
        if #available(iOS 26.0, *) {
            sharedBackgroundVisibility(.hidden)
        } else {
            self
        }
    }
}

Now the function hideSharedBackgroundIfAvailable can be used in place of the modifier sharedBackgroundVisibility in the code above:

ToolbarItem(placement: .topBarTrailing) {
    // content as before
}
.hideSharedBackgroundIfAvailable() // 👈 here

I would expect this to compile with all build targets from iOS 14.0 onwards.

use dark mode for screenshot
Source Link
Benzy Neez
  • 29.6k
  • 3
  • 22
  • 64

Try applying .sharedBackgroundVisibility(.hidden) to the ToolbarItem:

.toolbar {
    ToolbarItem(placement: .topBarTrailing) {
        Button {
        } label: {
            Image(systemName: "plus")
        }
    }
    .sharedBackgroundVisibility(.hidden) // 👈 here
}

ScreenshotScreenshot

Try applying .sharedBackgroundVisibility(.hidden) to the ToolbarItem:

.toolbar {
    ToolbarItem(placement: .topBarTrailing) {
        Button {
        } label: {
            Image(systemName: "plus")
        }
    }
    .sharedBackgroundVisibility(.hidden) // 👈 here
}

Screenshot

Try applying .sharedBackgroundVisibility(.hidden) to the ToolbarItem:

.toolbar {
    ToolbarItem(placement: .topBarTrailing) {
        Button {
        } label: {
            Image(systemName: "plus")
        }
    }
    .sharedBackgroundVisibility(.hidden) // 👈 here
}

Screenshot

Source Link
Benzy Neez
  • 29.6k
  • 3
  • 22
  • 64

Try applying .sharedBackgroundVisibility(.hidden) to the ToolbarItem:

.toolbar {
    ToolbarItem(placement: .topBarTrailing) {
        Button {
        } label: {
            Image(systemName: "plus")
        }
    }
    .sharedBackgroundVisibility(.hidden) // 👈 here
}

Screenshot