is it possible to create UIPickerView where there will be text and image in one row?
I know how to create it with text only:
class FirstViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
var currArray = ["USD","GBP"]
var flags = ["USD.jpg", "GBP.jpg"]
var picker = UIPickerView()
@IBOutlet weak var currencySelectorLabel: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
picker.delegate = self
picker.dataSource = self
currencySelectorLabel.inputView = picker
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return currArray.count
}
func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
currencySelectorLabel.text = currArray[row]
}
func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return currArray[row]
}
}
But I would like to have something like this:
Obviously instead of image files' names should be real images.
And I want to assign label text from UIPickerView as it is right now.
With help of this post How can I get images to appear in UI PickerView Component in Swift? everything seems to work!