UINavigationBar title font size in landscape
Asked Answered
D

1

7

Is there anyway I can set the font size for the UINavigationBar title in landscape mode?

I'm using the UIAppearance proxy to customize the title text attributes and I am specifically interested in the font size when in landscape. It's font in portrait but when rotating to landscape the font size does not shrink as the default behaviour.

[[UINavigationBar appearance] setTitleTextAttributes:[[NSDictionary alloc] initWithObjectsAndKeys:
                                           [UIFont fontWithName:@"Awesome-Bold" size:20], UITextAttributeFont,
                                           [UIColor colorWithWhite:0.0f alpha:0.2f], UITextAttributeTextShadowColor,
                                           [NSValue valueWithUIOffset:UIOffsetMake(0.0f, -1.0f)], UITextAttributeTextShadowOffset,
                                           [UIColor whiteColor], UITextAttributeTextColor,
                                           nil]];

Unfortunately I don't see any barMetric: property to go along with setTitleAttributes:.

Thanks.

Decalescence answered 4/12, 2012 at 2:0 Comment(0)
D
8

So after researching a bit online I find out the font size has to be set to 0 which ensures the font is automatically set to the appropriate size in landscape and portrait:

[UIFont fontWithName:@"Awesome-Bold" size:0], UITextAttributeFont
Decalescence answered 4/12, 2012 at 2:15 Comment(4)
I can't seem to get this to work. Where did you put this code?Lenient
It's part of the dictionary that is set above in setTitleTextAttributes:Decalescence
Sorry, I guess I didn't make myself clear -- I mean where in the app is the entire block of code that you posted? viewDiLoad? init? I've tried it all over the place, and I see no effect.Lenient
Sorry, I misunderstood. I usually customize my app's appearance in application:didFinishLaunchingWithOptions: I generally make a separate method -(void)customizeAppearance that I then call from application:didFinishLaunchingWithOptions:. Hope that helps.Decalescence

© 2022 - 2024 — McMap. All rights reserved.