Reputation: 549
iOS 14 provided a new .toolbar
implementation for the NavigationView. There is a placement parameter with options of .principal
, .navigationBarLeading
, and .navigationBarTrailing
.
I'd like to add a search bar in the Navigation bar. What is the proper way to achieve a fullwidth search bar?
My expectation was that I would be able to put the search bar on the left using navigationBarLeading and set the frame to full width.
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
HStack {
Text("Full width")
Spacer()
Text("Toolbar")
}.frame(width: .infinity)
}
}
Upvotes: 2
Views: 1720
Reputation: 21
I just had similar in the bottomBar. Maybe you can try. Cheers
ToolbarItem(placement: .navigationBarLeading){
Spacer()
}
ToolbarItem(placement: .principal){
HStack {
Text("Full width")
Spacer()
Text("Toolbar")
}
}
ToolbarItem(placement: .navigationBarTrailing){
Spacer()
}
Upvotes: 2