2

I'm building a UIPickerView to resemble a custom subclass of UIDatePicker, timepicker style.

Anyway, the minutes component should have numbers for every 5 minutes, starting with 00, 05, and then 10, 15, etc...

How do I get the zero number padding formatting on the left for the 00 and 05 minutes mark?

I suspect I have to delve into the NSNumberFormatter class, but I have no experience whatsoever with it, apart from it looking like quite a scary class, and I was hoping someone could give me a basic implementation in a quick punch.

MiguelB
  • 1,913
  • 18
  • 20

1 Answers1

10

Convert your int to NSStrings like so:

[NSString stringWithFormat:@"%02d", 1];

This int will be converted to 01.

Cyprian
  • 9,423
  • 4
  • 39
  • 73
  • Not quite what I had in mind, but since I have to return strings for the picker's rows anyway, this will work just fine. Thanks for the heads up. – MiguelB Jan 01 '12 at 16:04
  • To be avoid warnings today (2019+) NSInteger formatter must be like: [NSString stringWithFormat:@"%02ld", (long)value]; Thank you for answer. – MGY Aug 06 '19 at 11:41