Search code examples
objective-cfontsuinavigationcontrolleruibarbuttonitemback-button

Change font of back button on UINavigationController


I'm trying to change the font color of the text on my back button in my UINavigationControllerBar:

[[UIBarButtonItem appearance] setTitleColor:[UIColor redColor] forState:UIControlStateNormal];

I get this error:

[_UIBarItemAppearance setTitleColor:forState:]: unrecognized selector sent to instance 0x69aeb70'

Solution

  • Use this instead, default function available in iOS 5:

    UIBarButtonItem *backbutton = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:nil action:nil];
    
    [backbutton setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
        [UIColor blackColor],UITextAttributeTextColor,
        [UIFont fontWithName:TEXTFONT size:16.0f],UITextAttributeFont,nil]
        forState:UIControlStateNormal];