You can easily create a custom UIPickerView. Just download the source code from files.
- Create your Sections with
CustomPickerSection
.
var sections: [CustomPickerSection] = []
sections.append(CustomPickerSection(range: 220, suffix: " km", width: 35))
sections.append(CustomPickerSection(range: 1000, suffix: " m", width: 35))
- Over the
viewDidLoad()
method create a global customPicker.
let customPicker = CustomPickerDelegate()
- Set the sections for the
customPicker
.
customPicker.sections = sections
customPicker.resultView = textField
- Create a
UIPickerView
and set its dataSource and delegate to yourcustomPicker
.
let picker = UIPickerView()
picker.dataSource = customPicker
picker.delegate = customPicker
- Last set the just created
picker
as inputView to yourtextField
textField.inputView = picker