Change navigation bar title programmatically: Add a symbol and change its color
ios, objective-c, uikit, uinavigationcontroller, uiview
Solution
If your view controller is contained within a navigation controller, it is sufficient to set the title property:
self.title=@"Something •";
Xcode and NSStrings are fully UTF-8 compliant so putting the bullet right in the string like that is fine.
If you are trying to manipulate the navigation bar title independently, you will have to go through some hoops to find it. If you know that it's the root view controller then you could do something like:
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UINavigationController *navCtrl = (UINavigationController*)[keyWindow rootViewController];
UINavigationItem *topItem = [navCtrl topItem];
topItem.title = @"Something •";
Problem
I would like to add a character symbol (e.g. a whitespace character followed by a bullet symbol "•") to the title of my navigation controller's `UINavigationBar`. Depending on the state of my app, I would like to change the foreground color of the bullet. I thought about using an attributed string to be able to change the color. However, I did not find a way to access the title directly and assign it an attributed string. What solution would you recommend to add a character symbol to an `UINavigationBar` and to be able to change its color? Thank you!