On our app, we have a UIPickerView that lets you choose a season. However, on iOS 11, the Done button and Cancel button disappear and are only visible while switching between apps. Has anyone else experienced this?
Screenshots of iOS 11 behavior, with iOS 10 behavior below.
Edit: Here's a complete sample app with the issue:
Here's the code for setting up the picker view
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
}
Turns out there's a simple fix for this:
self.seasonPicker.translatesAutoresizingMaskIntoConstraints = false
Internally, looks like they've changed the behavior of input accessory views to have this property on by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With