Reputation: 347
I'm now working on putting segmented style picker inside NavigationBarItems. Here's the code I'm using:
struct ContentView: View {
let modes = ["temperature", "distance"]
var body: some View {
NavigationView {
ZStack {
...
}
}
.navigationBarItems (leading:
Picker ("Select mode:", selection: $currentMode) {
ForEach (0..<mods.count) {
Text(self.mods[$0])
}
}
.pickerStyle(SegmentedPickerStyle())
)
}
}
}
If I use leading:
the picker is shown on the left, if I use trailing:
then the picker is shown on the right. How can I put it in the centre?
Upvotes: 2
Views: 231
Reputation: 257711
Use .toolbar
instead, like
ZStack {
Text("Demo")
}
.toolbar {
ToolbarItem(placement: .principal) {
Picker ("Select mode:", selection: $currentMode) {
ForEach (0..<modes.count) {
Text(self.modes[$0])
}
}
.pickerStyle(SegmentedPickerStyle())
}
}
Upvotes: 1