'Scrolling to the selected item in Picker selection list of SwiftUI
I have following picker. The problem is the list Picker shows is scrollable and when selected value is near the end of the array user have to scroll manually. Is there a way to scroll to selected item automatically with a setting.
Menu {
Picker("", selection: $selectedItem) {
ForEach(0..<myArray.count, id: \.self) {index in
Text(myArray[index])
}
}
} label: {
HStack(spacing: 1) {
Text("Selection Name")
.foregroundColor(.white)
.frame(width: myWidth, height: myHeight, alignment: .trailing)
Text(myArray[$selectionIndex])
.frame(width: myWidth, height: myHeight, alignment: .center)
.multilineTextAlignment(.leading)
.background(Color.white)
.foregroundColor(.black)
.cornerRadius(5)
Text(myAffix)
.foregroundColor(.white)
.frame(width: myWidth, height: myHeight, alignment: .leading)
}
.foregroundColor(.white)
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
