r/SwiftUI • u/ducky_duck666 • 6d ago
Question iOS 27 changed textfield behavior in toolbars, how can I extend its width?
In iOs 26, with the exact same code, the controls at the bottom automatically went edge to edge on the bottom of the screen, but on 27, the textfield only extends to the width of the placeholder text inside of it. I can't figure out for the life of me how to get it to extend its width again! Any help would be very appreciated.
Code:
ToolbarItemGroup(placement: .bottomBar) {
TextField("Add Player", text: $newPlayer)
.font(.body)
.frame(maxWidth: .infinity)
.focused($isFocused)
.onSubmit(addPlayer)
.padding(.horizontal)
Button ("Add", systemImage: "plus") {
addPlayer()
}
.disabled(newPlayer.isEmpty || nextGamePlayers.contains(newPlayer))
.sensoryFeedback(.selection, trigger: nextGamePlayers)
Button("Play", systemImage: "play.fill", role: .confirm) {
isFocused = false
withAnimation {
menuShowing = false
gameSetupShowing = false
}
onEndGame?()
onStartGame?()
}
.sensoryFeedback(.selection, trigger: gameActive)
.disabled(nextGamePlayers.count < 2)
}
2
u/No_Pen_3825 5d ago
Honestly I’d take it out of the toolbar and put it at the end of the players section like maps does with add stop
1
u/ThanhDongNguyen 6d ago
I think in 27 the toolbar sizes items by their ideal size, so .frame(maxWidth: .infinity) inside ToolbarItemGroup just gets ignored. The bottom bar doesn't give the item extra space to grow anymore.
For an input row like this I would take it out of the toolbar and use safeAreaBar (26+, or safeAreaInset if you support older):
Inside a normal HStack the TextField takes all the leftover width, and the bar still moves up with the keyboard. You also don't depend on how Apple changes toolbar layout again next year.