Blog

We build amazing iPhone and iPad apps. We recently built ABC Play School Play Time and Art Maker for iPad, and recently wrote Learning Cocoa with Objective-C Fourth Edition and the iOS Game Development Cookbook for O'Reilly. This is our blog.

SLNumberPickerView

SLNumberPickerView is a control that presents a 3-digit number picker. It's very customisable, highly themable, and very easy to use. We made SLNumberPickerView after a designer, the marvellous @padschneider, crafted this look for a number picker:

SLNumberPickerView

Our first reaction: "argh, UIPickerView can't be made to look like that, no matter how many UIView hierarchy hacks you throw at it!"

Our second reaction: "hey, UIPickerView sucks anyway, let's make a better version for this problem!"

So, here's SLNumberPickerView. The image above it isn't from our PSDs, it's a screenshot from the working thing in the simulator.

It does one thing: present a suitcase-combination-lock-style interface to the user, which lets the user choose three digits. You can then query the view to get the integer value of the number the user's chosen. SLNumberPickerView also provides a delegate protocol that you can implement to be notified of any changes.

SLNumberPickerView keeps its own view hierarchy in a separate nib, which makes it very easy to theme - you can change the background colours, overlay images, and do all kinds of things with it.

SLNumberPickerView allows you to control the colour and font of the numerals, and also allows you to specify a tiled background image that is placed beneath the numerals. We added this in order to add the tick-marks that you see at the right of each column in the above screenshot.

How to use it

Download SLNumberPickerView from GitHub, and add the files to your project. SLNumberPickerView requires ARC.

Next, add an empty UIView to your interface. Size it to something like 145 wide by 100 high, and set its class to SLNumberPickerView. At runtime, the number picker view will be placed inside it.

You can query the number picker view for its value via the read-only value property:

Alternatively, you can conform to the SLNumberPickerViewDelegate protocol, which defines the following method:

Set yourself to be the delegate, and you'll receive messages every time the number selected by the user changes.

Caveats

SLNumberPickerView currently doesn't support setting a value programmatically.

It's available on GitHub now.