I'm currently developing an app using Swift where I use a UIPickerView, see below for image. Currently the UIPickerView stops when the user has scrolled to the last data, but i want it no never stop. I want it to be possible to start from the first data by just keep on scrolling when you're at the bottom. Or scroll up when at the top. I want it to be like Apple's Countdown where you can drag up or down whenever you want.
How I want it to be:
How it currently is:
There will be four steps here -- we'll set up some constants to hold the picker view data and a bit of configuration, then we'll add
UIPickerViewDataSource
andUIPickerViewDelegate
methods, and we'll end with theviewDidLoad
initialization.First, the configuration:
Note the
pickerViewMiddle
constant -- it's calculated to make it very easy to get our current value from the row offset. On to the data source -- we really only need to provide a title for each row, but we'll add a helper method to convert a row number to a value from the array:And finally we'll set up the delegate:
To initialize, in your
viewDidLoad
set the delegate and data source and then move to the correct row in the middle of your picker:This has already been answered here: How do you make an UIPickerView component wrap around?
The basic idea is that you simply create a picker view with a large enough number of repeating rows that the user will likely never reach the end. In the above answer there is an issue with how the number of rows is created so I have edited that piece and provided the remaining answer below. This is objective-c so you will need to convert it to swift for your purposes...