无论如何都可以在选择器中“填充”内容。比如Picker中的“Text”.padding()
Picker(selection: $picked) {
ForEach(0...10, id: \.self) { num in
Text("\(num)").tag("\(num)")
.font(.system(size: 30))
.foregroundColor(pickedMinute == "\(num)" ? .blue : .black)
.padding(20) // ***It does not work***
}
} label: {
Text("picker")
}
swiftui中的picker不支持padding 您可以创建一个带有填充的自定义选择器,如下所示:
ScrollView(.horizontal, showsIndicators: false) {
HStack {
ForEach(numbers, id: \.self) { number in
Text("\(number)")
.font(.system(size: 30))
.foregroundColor(self.pickedNumber == number ? .blue : .black)
.padding(20)
.onTapGesture {
self.pickedNumber = number
}
}
}
}