Hello,
I try to limit the width of a wheel style picker on iOS 15 using Xcode 13 beta5 in the code below. The drawing is correct, but the scroll areas of the elements overlap. So the toggle does not work and the the scrolling on the digits works with offset only. I have discovered this issue also on iOS 14.
Any idea how to fix this?
Matthias
import SwiftUI
struct ToggleButton: View {
var key: String
var systemImage: String?
@Binding var isSelected: Bool
var body: some View {
Toggle(isOn: $isSelected, label: {
if systemImage != nil {
Label(key, systemImage: systemImage!)
} else {
Text(key)
}
}).toggleStyle(.button)
}
}
struct DecimalPickerDigit: View {
var pos: Int
var height: CGFloat
var value: Int
var updateModel: (Int, Int)->Void
var body: some View {
Picker("", selection: Binding( get: { value },
set: { val in updateModel(val, pos) })
) {
ForEach(0 ..< 10, id: \.self) { i in
Text("\(i)")
}
}
.pickerStyle(.wheel)
.labelsHidden()
.frame(width: 20)
.frame(idealHeight: height, maxHeight: .infinity)
.clipped()
}
}
struct ContentView: View {
@State var isOn = false
@State var intVal1 = 0
@State var intVal2 = 0
var body: some View {
HStack {
ToggleButton(key: "Toggle", isSelected: $isOn)
DecimalPickerDigit(pos: 1, height: 100, value: intVal1, updateModel: { val, pos in intVal1 = val })
DecimalPickerDigit(pos: 1, height: 100, value: intVal2, updateModel: { val, pos in intVal2 = val })
}
}
}