I’m making an iPhone alarm clock app and I wanted two things for the time picker: military time and “infinite” circular scrolling like the default iOS clock app. I wanted military time in order to avoid the AM/PM mix-up that I can’t seem to shake. But unfortunately for me the default iOS UIPickerView for time supports circular scrolling but it doesn’t seem to support military time. So I made a segmented UIPickerView for military time and without circular scrolling it just felt wrong.
Now there’s no real api or obvious way in UIPickerView to implement circular scrolling.
After some googling around I found some people on stackoverflow who think that Apple’s implementation of UIPickerView is just a really really long list. And it seems they’re correct.
Open up the alarm app and you’ll see something like this:
Where it looks like the numbers scroll forever in both directions.
But if you scroll up long enough you get this:
That’s right, there is a beginning! And it’s 1 which makes sense because there isn’t a 0 time in the AM/PM scheme.
And if you scroll down long enough you get this:
Yes 4pm is the when the world ends. So says Apple.
So why 4? Well 216 mod 12 = 4. (Well 232 mod 12 = 4 and 28 mod 12 = 4 as well. But I feel like I scrolled far too long for it to be 28 and 232 rows causes the app to crash because there are too many rows).
For anyone who wants to reproduce this scrolling to the bottom is easier than scrolling to the top for some reason. And if you keep scroll after reaching the end the picker resets to the middle.
Here’s a link to my implementation of an this if anyone’s interested.