【发布时间】:2020-08-20 02:55:49
【问题描述】:
我通过调用下面的视图在 HStack 中创建一组并排选择器。每个选择器的“控制”区域在选择器左侧比应有的要宽得多。 “.clipped()” 应该解决这个问题,但它不起作用。在我开发代码的某个时候,它可以工作,但现在我无法取回它。当我尝试操纵选择器时,我可以将最右边的选择器移动到右侧 3 列的任意位置。左列根本无法操作。这是怎么回事?
struct SinglePickerView: View {
@Binding var note: Int
let notes: [String]
let width: CGFloat
var body: some View {
VStack {
ZStack (alignment: .center) {
RoundedRectangle(cornerRadius: 5)
.fill(Color(red: 192, green: 192, blue: 192))
.frame(width: width-10, height: 25)
Text("\(notes[note])")
.foregroundColor(.black)
}
Picker(selection: $note, label: Text("")) {
ForEach(0 ..< 72) { index in
Text("\(self.notes[index])")
.foregroundColor(.white)
.tag(index)
}
}
.labelsHidden()
.frame(width: width)
.clipped()
}
}
}
【问题讨论】: