I would like to limit the tappable area of the picker in a form to only it's visible area of text (i.e. black rectangle in the picture below). Currently whole row can be tappable.
Here is the code:
import SwiftUI
struct ContentView: View {
@State var rate: String = ""
@State var units = ["mL/day","mL/hour"]
@State var unit: Int = 0
var body: some View {
NavigationView{
Form{
HStack{
Text("Rate")
TextField("0", text: $rate)
Picker(selection: $unit, label: Text(""), content: {
ForEach(0..<units.count, content: { unit in
Text(units[unit])
})
})
.frame(width: 100.0)
.compositingGroup()
.clipped()
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I read through this question and try to add .clipped()
and .compositingGroup()
but seems not useful.