Prevent UiNavigationBar Title from getting Cut off?
Asked Answered
M

2

6

I am trying to customize the appearance of the navigationBar title in my ios application. This is the code I currently have:

NSMutableDictionary *navigationTitleAttributes = [NSMutableDictionary dictionary];
[navigationTitleAttributes setValue:[UIColor whiteColor] forKey:UITextAttributeTextColor];
[navigationTitleAttributes setValue:[UIColor clearColor] forKey:UITextAttributeTextShadowColor];
[navigationTitleAttributes setValue:[NSValue valueWithUIOffset:UIOffsetMake(0.0, 0.0)] forKey:UITextAttributeTextShadowOffset];
[navigationTitleAttributes setValue:[UIFont fontWithName:@"Calibri" size:30] forKey:UITextAttributeFont];


[[UINavigationBar appearance] setTitleTextAttributes:navigationTitleAttributes];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-8 forBarMetrics:UIBarMetricsDefault];

The code yields the following effect:

SCreenshot

It works great but my title gets cut off from the bottom.

I've seen solutions to this problem that use a custom UIView (such as this one: UINavigationbar title is cut off when using titleTextAttributes). However, that particular solution requires that the titleView property of the navigation bar be updated for each screen.

I was wondering if there was a simple solution that would cascade through my entire application.

Thanks

Mundell answered 17/8, 2013 at 22:4 Comment(0)
C
0

Th simple solution is to not use such a large font size. If you set the size to zero then the text should be auto-sized as appropriate.

Otherwise, using a custom view is the correct solution. You can subclass the navigation controller or navigation bar in order to ensure that all of the views have the label styled in the same way.

Canula answered 17/8, 2013 at 22:27 Comment(2)
Setting the font size to zero to auto-size the text is a great tip, works well.Rotogravure
this makes it disappear for mePenchant
L
0

If you're using a custom font, you may be having the same problem I was. I found a few answers on this post to be quite helpful. I changed my descender values in my .otf font file to prevent my font from being cut off on the bottom. It was especially prevalent in iOS 7.

Custom installed font not displayed correctly in UILabel

Libel answered 14/10, 2013 at 18:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.