首页 > 解决方案 > Swift UI - Wheel Picker,更改对齐方式和字体大小

问题描述

是否可以自定义车轮选择器字体并将对齐方式更改为.leading

标签: iosswiftuipicker

解决方案


我想这将是你所期望的。

struct ContentView: View {
    let colors = ["Red", "Yellow", "Green", "Gray", "Black", "Purple", "White", "Brown", "Pink", "Blue"]
    @State private var color = "Red"
    var body: some View {
        Picker(selection: $color, label: Text("")) {
            ForEach(self.colors, id: \.self) { color in
                HStack {
                    Text(color)
                        .font(.title)
                        .padding()
                    Spacer()
                }
            }
        }
        .pickerStyle(WheelPickerStyle())
        .labelsHidden()
    }
}

谢谢,X_X


推荐阅读