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?
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))
}
}
}