Search code examples
swiftuipaddingpicker

SwiftUI Picker: The padding of content in Picker does not work


Is there anyway to "padding" content in the picker? Such as 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")
}

Solution

  • What does work is the .font modifier. And what also works is .scaleEffect. Used in combination, you can get a larger font with more spacing:

    Picker(selection: $picked) {
        ForEach(0...10, id: \.self) { num in
            Text("\(num)").tag("\(num)")
                .font(.system(size: 15))
                .foregroundColor(pickedMinute == "\(num)" ? .blue : .black)
        }
    } label: {
        Text("picker")
    }
    .pickerStyle(.wheel)
    .scaleEffect(2)
    

    Screenshot