Search code examples
objective-cuitabbarxcode4.5

How to make texts in UINavigation Bar Centered Vertically


I do this:

[[UINavigationBar appearance] setTitleTextAttributes:@{UITextAttributeTextColor: navTextColor,UITextAttributeTextShadowColor: navTextColor,UITextAttributeTextShadowOffset: [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],UITextAttributeFont: [UIFont fontWithName:@"HelveticaNeue-Bold" size:12],UITextAttributeFont: [UIFont fontWithName:@"HelveticaNeue-Bold" size:12]}];

The result is the text is smaller. However, it's posted too high.

enter image description here

I can fix that using

[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:5 forBarMetrics:UIBarMetricsDefault];

But sometimes I want to use UIText rather than just pics on the titleView and that get pushed down too.

It would be a very strange design I think to have text goes up like that. So what's the catch and how do I make title texts in UINavigationBar centered vertically as it is horizontally.


Solution

  • One solution is Check this answer.

    Other solution is set the frame of your label view. check this answer