swiftUI picker(Picker 中内容的填充不起作用)

问题描述 投票:0回答:1

无论如何都可以在选择器中“填充”内容。比如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 padding picker
1个回答
0
投票

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
                        }
                }
            }
        }
© www.soinside.com 2019 - 2024. All rights reserved.