0

i have been using what i had thought to be some fairly standard iOS 5 code (and which is a 7x accepted answer on stackoverflow) in order to have my UINavigationBar's title appear with a customized font.]

but i have discovered that when my app built for iOS5 (so that it can run on both iOS5 and iOS6 devices) is run on the iOS6 simulator, it ellipsizes my title.

iOS 4 inch Retina display simulator running iOS 6.0

the following is the same code running on the iOS 5.1 simulator.

iOS 3.5 inch Retinda display simulator running iOS 5.1

for clarity, the following is the pertinent code that's been working until i tried running on iOS 6.

#define COURIER_FONT_BOLD @"CourierNewPS-BoldMT"

- (UIFont*)navigationBarTitleFontPortrait
{
    if (!_navigationBarTitleFontPortrait)
        _navigationBarTitleFontPortrait = [UIFont fontWithName:COURIER_FONT_BOLD size:24.0];
    return _navigationBarTitleFontPortrait;
}

// …

    if ([[UINavigationBar class] respondsToSelector:@selector(appearance)])
    {
        NSDictionary* attrs = [NSDictionary dictionaryWithObjectsAndKeys:
                                            [UIColor lightGrayColor],
                                                                UITextAttributeTextShadowColor,
                                            [NSValue valueWithUIOffset:UIOffsetMake(1, 0)],
                                                                UITextAttributeTextShadowOffset,
                                            navigationBarTitleFontPortrait,
                                                                UITextAttributeFont,
                                            nil];
        [[UINavigationBar appearance] setTitleTextAttributes:attrs];
    }
Community
  • 1
  • 1
john.k.doe
  • 7,533
  • 2
  • 37
  • 64

1 Answers1

3

i discovered two solutions to the above problem:

  1. set the title text to something of a different size in the .storyboard (in my case, i entered "...", and then in viewDidLoad, call self.navigationItem.title = @"the GRID";

  2. in viewDidLoad, perform [self.navigationController.navigationBar setNeedsLayout].

i prefer the latter because it feels less like a kludge. i am guessing the first solution forces the second to happen, anyway.

don't know why this behavior is different between iOS 5 and iOS 6, but this allows it to work in both.

john.k.doe
  • 7,533
  • 2
  • 37
  • 64