Quantcast
Channel: Active questions tagged uipickerview - Stack Overflow
Viewing all articles
Browse latest Browse all 592

UIPickerView text plus image

$
0
0

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:

enter image description here

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!


Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>