Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIPickerView changed on iOS 11?

Tags:

ios

ios11

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

}

UIPickerView with missing done button UIPickerView's done button reappears while switching between views UIPickerView working as expected on iOS 10

like image 859
StevenOjo Avatar asked Dec 24 '22 17:12

StevenOjo


1 Answers

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.

like image 65
StevenOjo Avatar answered Jan 06 '23 05:01

StevenOjo