Skip to content

Instantly share code, notes, and snippets.

@quangtqag
Created July 21, 2016 07:04
Show Gist options
  • Save quangtqag/c63b5a70b1e3c9131c8a78ecf423d13e to your computer and use it in GitHub Desktop.
Save quangtqag/c63b5a70b1e3c9131c8a78ecf423d13e to your computer and use it in GitHub Desktop.
func adjustNavigationBarTitleToVisibleFullText() {
let titleLabel = UILabel(frame: CGRectMake(0, 0, 1000, 44))
titleLabel.text = self.title
titleLabel.numberOfLines = 2
titleLabel.font = UIFont.GBNavigationBarFont()
titleLabel.textAlignment = NSTextAlignment.Center
titleLabel.textColor = UIColor.GBNavigationBarForegroundColor()
titleLabel.adjustsFontSizeToFitWidth = true
self.navigationItem.titleView = titleLabel
}
func adjustNavigationBarTitleToDefault() {
self.navigationItem.titleView = nil
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
adjustNavigationBarTitleToVisibleFullText()
}
override func viewWillDisappear(animated: Bool) {
super.viewWillDisappear(animated)
adjustNavigationBarTitleToDefault()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment