Currently, I am changing the font of the navigation bar using the following in the AppDelegate
:
[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"..." size:...], NSFontAttributeName,
nil]];
Is there a way to do the same to make sure that the string is capitalized globally?
It's not possible to achieve this using NSAttributedString, but instead you can change the title in your base view controller class. Try this:
/// Base class for all view controllers
class BaseViewController: UIViewController {
private var firstWillAppearOccured = false
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if !firstWillAppearOccured {
viewWillFirstAppear(animated)
firstWillAppearOccured = true
}
}
/// Method is called when `viewWillAppear(_:)` is called for the first time
func viewWillFirstAppear(_ animated: Bool) {
title = title?.uppercased() // Note that title is not available in viewDidLoad()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With