0

I have a ForEach inside a picker with numbers from 0 to 20 that shows 0, 1, 2...20 but instead I need to display 00, 01, 02...20. How can I do it?

xmetal
  • 551
  • 4
  • 12

1 Answers1

2

You use the normal string formatting String(format: "%02d", 5):

@State var num: Int = 0

var body: some View {
   Picker("", selection: $num) {
      ForEach(0..<21) { v in 
         Text(String(format: "%02d", v)) 
      }
   }
}
New Dev
  • 46,536
  • 12
  • 79
  • 122