Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:06:29+00:00 2026-06-14T13:06:29+00:00

I’m trying to customize my UINavigationBar font, using the following code for iOS 5

  • 0

I’m trying to customize my UINavigationBar font, using the following code for iOS 5 in my app delegate’s application:didFinishLaunchingWithOptions:

if ([[UINavigationBar class] respondsToSelector:@selector(appearance)]) 
{
    [[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: 
                                                          [UIColor whiteColor], UITextAttributeTextColor,
                                                          [UIColor blackColor], UITextAttributeTextShadowColor,
                                                          [NSValue valueWithUIOffset:UIOffsetMake(1, 0)], UITextAttributeTextShadowOffset,
                                                          [UIFont fontWithName:kDefaultFont size:0.0], UITextAttributeFont, 
                                                          nil]];
}

It works fine and the navigation bar is rendered using my font. Great.

The references I’ve found suggest that you can use the font size of zero and it will resize the font to fit your navigation bar (using a slightly smaller font for the shorter navigation bar for the landscape layout). And it does choose a font size that fits nicely to the height of the navigation bar. But it looks like if you go from portrait to landscape and back, the width of the navigation bar’s title label gets screwed up, so what shows up as a title of, for example, “Long Titlebar”, looks fine when you first view it in portrait orientation, looks fine when you view it in landscape (with the appropriately smaller font), but when I come back to portrait, the font correctly reverts to the larger font, but the title text itself is truncated, becoming “Long…” even though there’s plenty of space for the full title. Has anyone else seen this behavior when using a font size of 0.0?

Clearly, I can just specify an actual font size (in which case I don’t see this truncating behavior), but then I’m manually figuring out what size to use. And worse, the font size is the same for landscape and portrait, so right now I’m using a font size that fits in the shorter landscape navigation bar title and the title is smaller than it needs to be in the taller portrait navigation bar.

Has anyone out there had experience with using setTitleTextAttributes to change the font of the [UINavigationBar appearance] in such a way that the font size changes between portrait and landscape, but not having this truncation of the title when you return back to portrait after going to landscape? I’m about to pursue various kludgy workarounds, but if you have any experience in this issue, let me know.

Update:

In the process of submitting this bug to Apple, I decided to demonstrate how to reproduce the problem:

  1. Create new iOS Master-Detail Application in Xcode 4.3.2.

  2. Put the above setTitleTextAttributes code in the app delegate’s application:didFinishLaunchingWithOptions (I used the font @”GillSans”).

  3. Go to MasterViewController and add line that says self.title = @"Long Title";

  4. Comment out the UIBarButtonItem *addButton code.

  5. Run the program. Note the title correctly says “Long Title”. Rotate to landscape. Still looks good. Rotate back to portrait and the title now says “Long…” even though there’s plenty of space.

  6. Curiously, if you restore the UIBarButtonItem *addButton code, the title works as it should. But if you either eliminate the UIBarButton item, or replace it with a button that uses initWithTitle rather than initWithBarButtonSystemItem, you get the problem with the navigation bar title after rotating from portrait to landscape and then back to portrait.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:06:31+00:00Added an answer on June 14, 2026 at 1:06 pm

    the following is my workaround for this problem, and here’s the comment that appears next to my workaround implementation in each case as a reminder to myself as to why i implemented this bit of code:

    // when using an appearance proxy to set a custom font for the navigation bar (generally in
    // application:didFinishLaunchingWithOptions: in the appDelegate code) for both iOS 5 & 6,
    // there's a glitch that incorrectly auto-truncates the title in the following cirumstances:
    //
    // 1) when a 0.0 value is used for UITextAttributeFont in the titleTextAttributes dictionary
    //    and a device/simulator running pre-iOS 5 rotates back to portrait from landscape
    //    solution: perform [self.navigationController.navigationBar setNeedsLayout] in
    //              didRotateFromInterfaceOrientation: the view controller in which the
    //              auto-truncation is incorrectly occurring for systemVersion < 6.0
    //
    // 2) when a view initially loads running iOS 6 for a non-0.0 value for the UITextAttributeFont
    //    in the titleTextAttributes dictionary
    //    solution: perform [self.navigationController.navigationBar setNeedsLayout]
    //              in viewDidLoad in the view controller in which the auto truncation is
    //              incorrectly occurring for systemVersion >= 6.0
    

    so, for the cases where i’m ok with using the 0.0 value for UITextAttributeFont but have to continue supporting iOS5, i use solution (1):

    #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
        if (UIInterfaceOrientationIsPortrait(self.interfaceOrientation)
            && UIDevice.currentDevice.systemVersion.floatValue < 6.0)
            [self.navigationController.navigationBar setNeedsLayout];
    }
    #endif
    

    and in the couple of cases of legacy code where i wanted to support iOS 6 and fix the glitch when the view first appears without having to re-write the MyAppAppearance class methods i have that set non-0.0 values for my [UINavigationBar appearance] titleTextAttributes, i found it easier to implement the solution (2) thus:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    #if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0
        if (UIDevice.currentDevice.systemVersion.floatValue >= 6.0)
    #endif
            [self.navigationController.navigationBar setNeedsLayout];
    
        // … other viewDidLoadCode
    

    (and the __IPHONE_OS_VERSION_MIN_REQUIRED bracket just helps remind me which code can eventually go away if desired in the future, and which may have to stay.)

    to see a little more exactly what happens here, particularly in the case of the rotation, run the simulator with slow animations toggled.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.