The button is created like this:

// FIXME: не работает в iOS 10 !!! languageTopBarButton = UIButton(type: .custom) languageTopBarButton.setImage(UIImage(named: "iconGlobe"), for: .normal) languageTopBarButton.setTitle(title, for: .normal) languageTopBarButton.setTitleColor(UIColor.green, for: .normal) languageTopBarButton.addTarget(self, action: #selector(rightNavButtonTapped), for: .touchUpInside) let navBarHeight = navigationController?.navigationBar.frame.size.height var rightButtonFrame = languageTopBarButton.frame rightButtonFrame.size = CGSize(width: rightButtonFrame.width, height: navBarHeight!) languageTopBarButton.frame = rightButtonFrame let buttonItem = UIBarButtonItem(customView: languageTopBarButton) navigationItem.rightBarButtonItem = buttonItem 

in iOS 11, everything is fine with it, but in iOS 10 it does not appear:

enter image description here

What is wrong doing?

    1 answer 1

    In iOS10, when creating a button with this code, the width of the button frame remains undefined. If you add, for example, sizeToFit (), after the button has the title and image properties (or set the width manually), the frame width takes the current value and the button becomes visible:

     // ... languageTopBarButton.addTarget(self, action: #selector(rightNavButtonTapped), for: .touchUpInside) languageTopBarButton.sizeToFit() // <-- добавим эту строку в код из вопроса let navBarHeight = navigationController?.navigationBar.frame.size.height // ... 

    enter image description here