我有以下选择器。问题是选择器显示的列表是可滚动的,当所选值接近数组末尾时,用户必须手动滚动。有没有办法通过设置自动滚动到所选项目。
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)
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
303 次 |
| 最近记录: |