Skip to content

Instantly share code, notes, and snippets.

@automactic
Created January 10, 2018 02:14
Show Gist options
  • Save automactic/21810d9c1f63588d2e14d03a4fcf8bea to your computer and use it in GitHub Desktop.
Save automactic/21810d9c1f63588d2e14d03a4fcf8bea to your computer and use it in GitHub Desktop.
Broken iOS 11 NavigationBar
import UIKit
class ViewController: UIViewController {
let button = UIBarButtonItem(barButtonSystemItem: .add, target: nil, action: nil)
override func viewDidLoad() {
super.viewDidLoad()
let searchBar = UISearchBar()
searchBar.searchBarStyle = .minimal
navigationItem.titleView = searchBar
}
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
if traitCollection.horizontalSizeClass == .regular {
navigationItem.leftBarButtonItem = button
} else {
navigationItem.leftBarButtonItem = nil
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment