Reputation: 603
I would like to place a SegmentedControl or just a Button inside the center of the NavigationBar by using SwiftUI. I could place it on the trailing and leading part but not in the center.
Upvotes: 1
Views: 739
Reputation: 871
In SwiftUI 2.0, Xcode 12, You could achieve like below:
VStack {
....
}
.toolbar {
ToolbarItem(placement: .principal) {
Picker(selection: $selectionIndex,
label: EmptyView()) {
Text("Option 1").tag(0)
Text("Option 2").tag(1)
}
.labelsHidden()
.pickerStyle(SegmentedPickerStyle())
}
ToolbarItem(placement: .navigationBarLeading) {
leadingNavigationBarItem
}
}
Upvotes: 2
Reputation: 13256
This is not currently possible. navigationBarTitle(...)
only accepts Text
. Documentation here.
Upvotes: 0