在我们的应用程序中,我们有一个 UIPickerView 可让您选择季节。但是,在 iOS 11 上,完成按钮和取消按钮会消失,并且仅在应用程序之间切换时可见。有没有其他人经历过这个?
iOS 11 行为的屏幕截图,下面是 iOS 10 行为。
编辑:这是一个完整的示例应用程序:
这是设置选择器视图的代码
func setUpPickerView(){
self.seasonPicker = UIPickerView.init(frame: CGRect.init(x: 0, y: 50, width: self.frame.width, height: UIScreen.main.bounds.height / 3))
self.seasonPicker.delegate = self
self.seasonPicker.dataSource = self
self.seasonTextField.inputView = self.seasonPicker
let toolbar = UIToolbar.init(frame: CGRect.init(x: 0, y: 0, width: self.frame.width, height: 50))
toolbar.barStyle = UIBarStyle.default
let labelTitle = UILabel.init(frame: CGRect.init(x: 0, y: 50, width: 150, height: 20))
labelTitle.backgroundColor = UIColor.clear
labelTitle.textColor = UIColor.black
labelTitle.textAlignment = NSTextAlignment.left
labelTitle.text = "Select a Season"
labelTitle.sizeToFit()
let typeFeild = UIBarButtonItem.init(customView: labelTitle)
let cancelButton = UIBarButtonItem.init(title: "Cancel", style: UIBarButtonItemStyle.plain, target: self, action: #selector(didClickPickerCancel))
let flexSpace = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.flexibleSpace, target: nil, action: nil)
let doneButton = UIBarButtonItem.init(title: "Done", style: UIBarButtonItemStyle.plain, target: self, action: #selector(didClickPickerDone))
toolbar.items = [cancelButton, flexSpace, typeFeild, flexSpace, doneButton]
toolbar.sizeToFit()
self.seasonTextField.inputAccessoryView = toolbar
}