我将UIPickerView
作为UITextField
的输入,并使用"完成"实现UIToolbar
。按钮。它完美无缺,但当我在iPhone上切换到横向模式时,UIToolbar
消失了。这是我的代码:
override func viewDidLoad() {
super.viewDidLoad()
thePicker.delegate = self
let toolBar = UIToolbar()
toolBar.barStyle = UIBarStyle.default
toolBar.isTranslucent = true
toolBar.tintColor = UIColor(red: 76/255, green: 100/255, blue: 217/255, alpha: 1)
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(title: "Aceptar", style: UIBarButtonItemStyle.plain, target: self, action: #selector(doneClick))
toolBar.setItems([doneButton], animated: false)
toolBar.isUserInteractionEnabled = true
testTextField.inputView = thePicker
testTextField.inputAccessoryView = toolBar
}
答案 0 :(得分:0)
当我以编程方式添加UIPickerView并为PickerView添加UIToolBar时,遇到了相同的问题。只需为UIPickerView添加[.flexibleWidth,.flexibleHeight]
self.thePicker.autoresizingMask = [.flexibleWidth,.flexibleHeight]