If .topBarPinnedTrailing is used for the placement of a ToolbarItem, if this item is the only one in the toolbar then it is not displayed.
This .topBarPinnedTrailing appeared in iOS 27.0 to allow a button to be always visible in the toolbar if when there are overflows with many buttons in the toolbar. A toolbar button should always be visible, this behaviour is a bug.
It is a great issue on iPhone Duo which has less space for buttons in the toolbars, this attribute was designed to be sure the button using this attribute would always be visible. Bug is also there on Mac Catalyst and visionOS.
A feedback was created FB24882292
/// Shows a View with a toolbar with a .topBarPinnedTrailing button.
/// If the tool is the only one, it is not displayed. It is designed to be always visible, but it can be missing on the screen.
/// If there are one or more additional buttons, then the .topBarPinnedTrailing is well displayed.
///
/// Bug reproduced on iPhone 18 Pro Max simulator 27.0, iPhone Duo simulator iOS 27.1,
/// Mac Catalyst 27.0, Vision Pro simulator visionOS 27.0
/// > Warning : to test this ContentView, embed it in a NavigationStack.
struct ContentView: View {
@State private var twoButtons = false
var body: some View {
VStack {
Text("A toolbar should be always visible")
.padding()
Button {
twoButtons.toggle()
} label: {
Text(twoButtons ? "Remove second tool" : "Add second tool")
}
}
.toolbar {
// ‼️ this button is missing if it is the only one.
// ‼️ This is due to .topBarPinnedTrailing which makes it disappear if it is alone.
ToolbarItem(placement: .topBarPinnedTrailing) {
Button {
print("topBarPinnedTrailing pressed")
}
label: {
Label {
Text("topBarPinnedTrailing")
} icon: {
Image(systemName: "ladybug.fill")
}
.labelStyle(.iconOnly)
}
}
if twoButtons {
ToolbarItem(placement: .topBarTrailing) {
Button { //Barre d'icône ajouter une scène
print("topBarLeading pressed")
twoButtons = false
}
label: {
Label {
Text("topBarLeading")
} icon: {
Image(systemName: "minus")
}
.labelStyle(.iconOnly)
}
}
}
}
}
}