Lumialxk Lumialxk - 6 months ago 11
Swift Question

How to set custom font for backBarButtonItem

When there was no left bar items, navigation bar will gives a

backBarButtonItem
like
<Back
. But I can't find anyway to set font for it. Please help me! Many thanks in advance!

Answer

Swift:

UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont.fontNamesForFamilyName("Futura-Medium"), NSForegroundColorAttributeName:UIColor.whiteColor()], forState: UIControlState.Normal)

Objective-C:

[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                          [UIColor colorWithRed:245.0/255.0 green:245.0/255.0 blue:245.0/255.0 alpha:1.0], NSForegroundColorAttributeName,
                                                          shadow, NSShadowAttributeName,
                                                          [UIFont fontWithName:@"Futura-Medium" size:15.0f], NSFontAttributeName, nil] forState:UIControlStateNormal];