after using this code to custom the UINavigationBar title appearance, the label with text gets truncated, as the image below shows:
[[UINavigationBar appearance] setTitleTextAttributes:@{
UITextAttributeTextColor : [UIColor whiteColor],
UITextAttributeFont : [UIFont fontWithName:@"Intro" size:20.0f],
UITextAttributeTextShadowColor : [UIColor clearColor]
}];
And, as you can see, there is enough space.
Any ideas?
I've done a fair bit of testing in a clean project with a few dozen built-in fonts at various sizes, and I think I can state with some confidence that the label sizing issues found in earlier versions of iOS have been fixed in (or before) iOS 9.
The use case decribed in the original question does not seem to be reproducible, and the title label now seems to resize properly on its own. As such, I don't think it's necessary to update the layout manually anymore.
If you are still seeing truncation issues when there is clearly plenty of visual space available in the navigation bar, there are a few things you could try:
UILabel
and setting it as the navigation bar's titleView
, you can stop doing that, and just set the title normally.titleView
. That includes the code found in the originally accepted answer below.Original Answer
There are some known issues with UINavigationBar layout. Try updating the layout when the view controller appears, and/or on rotation.
- (void)viewDidLoad
{
[super viewDidLoad];
...
[[[self navigationController] navigationBar] setNeedsLayout];
}
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