This is part 2 of the Swift Picker View tutorial and in it you learn how to do display item images and names in a single component of PickerView. Here’s what the ViewController.swift file looks like now:
Code presented on this page assume you are using Xcode 6.4 and Swift version 1.2. So if you are using a newer version of Swift, it may produce errors. Fix them by using Xcode’s Fix-it tool.
Display Text and Images in The PickerView
As of now, the single component of the pickerView is configured to display only item names in its rows. The item names are stored in the pickerView’s data source. It is an array called, itemNameList. Now, to display item images and names in a single component of the pickerView, you’ll have to do the following in the viewController.swift file.
Declare an array variable.
var itemPhotoList = [UIImage]()
In the viewDidLoad() function add eight image names in the itemPhotoList array.