2

I need help creating an UIPickerView to wrap around the options. So instead of the picker looking like this:

right now

I want it to look like this (without the "min"):

what I want

I looked everywhere, but I can't find a way to do it with Swift 2.0 Thanks!

Alberto O.
  • 835
  • 1
  • 8
  • 14

2 Answers2

3

Here is an explanation that makes for quicker use:

Goal:

Make your UIPickerView larger than the user will ever try to scroll

Steps:

(1) Extend your picker in size

func pickerView(numberOfRowsInComponent) -> Int {
    return 10_000;
} 

(2) Access by Modulus

func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
    return data[row%data.count];
}

(3) Init to Middle (after init)

picker.selectRow((10_000/2), inComponent: 0, animated: false);
J-Dizzle
  • 4,861
  • 4
  • 40
  • 50
2

You can return a very large number in

func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int

and select the middle row while initialzing with

selectRow(COUNT/2, inComponent: 0, animated: true)

See this code sample

Quanlong
  • 24,028
  • 16
  • 69
  • 79