我正在以编程方式在文本字段单击上实现选择器视图。
这是我的功能:
func pickUpMarque(_ textField : UITextField){
// UIPickerView
self.PickerViewCarMarque = UIPickerView(frame:CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 216))
self.PickerViewCarMarque.delegate = self
self.PickerViewCarMarque.dataSource = self
self.PickerViewCarMarque.backgroundColor = UIColor.white
TextFieldCarMarque.inputView = self.PickerViewCarMarque
// ToolBar
let toolBar = UIToolbar()
toolBar.barStyle = .default
toolBar.isTranslucent = true
toolBar.tintColor = UIColor(red: 92/255, green: 216/255, blue: 255/255, alpha: 1)
toolBar.sizeToFit()
// Adding Button ToolBar
let doneButton = UIBarButtonItem(title: "Valider", style: .plain, target: self, action: #selector(AddCarViewController.doneMarqueClick))
let spaceButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let cancelButton = UIBarButtonItem(title: "Fermer", style: .plain, target: self, action: #selector(AddCarViewController.cancelMarqueClick))
toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false)
toolBar.isUserInteractionEnabled = true
TextFieldCarMarque.inputAccessoryView = toolBar
}
问题是当我点击textField时,它会系统地启动默认键盘。如果我禁用Xcode的编辑功能,则什么也不会显示。
我只想显示选择器视图而不是键盘。
能给我个解决办法吗?
谢谢。