Created
January 10, 2018 02:14
-
-
Save automactic/21810d9c1f63588d2e14d03a4fcf8bea to your computer and use it in GitHub Desktop.
Broken iOS 11 NavigationBar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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