I want to tag both textfield ana and sampleTextfield. So that in the extension field I can do things like call different pickerviews for each textfireld. Example:
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
if tag ==1 {
return firstHit[row]
} else {
return sendHit[row]
} }
Code:
var ana = UITextField(frame: CGRect(x: -20, y: 100, width: 300, height: 40))
var sampleTextField = UITextField(frame: CGRect(x: 20, y: 100, width: 300, height: 40))
extension ViewController: UIPickerViewDelegate, UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return firstHit.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return firstHit[row]
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
selecteDay = firstHit[row]
sampleTextField.text = selecteDay
}
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
var lable: UILabel
if let view = view as? UILabel {
lable = view
} else {
lable = UILabel()
}
lable.textColor = .white
lable.textAlignment = .center
lable.font = UIFont(name: "Menlo-Regular", size: 17)
lable.text = firstHit[row]
return lable
}}