Creating a custom UIPickerView
2012-08-06 Updated 2025-12-31 · 8c48a1bIn this tutorial I will create a simple iPhone app to demonstrate how one would create a UIPickerView with custom contents. I started by creating a single view iPhone app (If you are not familiar with this I suggest you read this).
Note: I always use Automatic Reference Counting unless specified otherwise.
Ok, lets jump right in and add a Picker View to the View on the storyboard and link it up to the ViewController.h file:

Now lets make sure that ViewController is part of the UIPicker protocols:
Now lets switch to ViewController.m and do the rest of the work.
First lets set up an array to store some of our list items in, we do this in the private interface:
Now go to the viewDidLoad function so we can give pickerView some settings, we set the dataSource and delegates to be self and set some other settings. Here we will also populate our array with some names:
- viewDidLoad
Next we Implement the Picker Delegate methods that will populate the pickers list. First is numberOfComponents... which returns the amount of "Columns" that the picker will contain, in this case only one.
-numberOfComponentsInPickerView:pickerView
Next is the method that returns the amount of items that will be in the list, so naturally we return the array count:
-pickerView:pickerView numberOfRowsInComponent:component
And Finally the method that will return the actual entry displayed in the pickerView:
-pickerView:pickerView titleForRow:row forComponent:component
Now just hit run and you should get the following result:

And for those of you who just want the source, here it is:
ViewController.h:
//
// ViewController.h
// pickerTest
//
// Created by Divan Visagie on 2012/08/06.
// Copyright (c) 2012 Divan. All rights reserved.
//
ViewController.m:
//
// ViewController.m
// pickerTest
//
// Created by Divan Visagie on 2012/08/06.
// Copyright (c) 2012 Divan. All rights reserved.
//
Note on wrapping: The UIPickerView is actually a glorified UITableView in a sense meaning that the "Spin Box" will not wrap automatically. This will require you to perform your own additional logic to get the job done if a spinbox is the look you are going for.
Originally posted on Blogspot