UIPickerView

UIPickerView.playground is an starting point to experiment with UIPickerView in an interactive playground:

UIView

import UIKit
import PlaygroundSupport

class PickerData : NSObject, UIPickerViewDataSource, UIPickerViewDelegate {
    let fruits = ["Apple", "Orange", "Banana"]

    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return fruits.count
    }

    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return fruits[row]
    }
}

let pickerData = PickerData()
let pickerView = UIPickerView()
pickerView.backgroundColor = .white
pickerView.dataSource = pickerData
pickerView.delegate = pickerData
pickerView.reloadAllComponents()

PlaygroundPage.current.liveView = pickerView
Btn training bbbdf557d2 Next iOS training: 25. Februar - 01. März 2019, Stuttgart
Btn about 5378472193 About me · Contact