0

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!

Lumialxk
  • 6,239
  • 6
  • 24
  • 47
  • You can use attributed text --- et barButtonBackStr = "< Back" let attributes: [String: AnyObject] = [NSFontAttributeName: UIFont(name: "AmericanTypewriter-Bold", size: 18)!] let newBackButton = UIBarButtonItem(title: barButtonBackStr, style: UIBarButtonItemStyle.Plain, target: self, action: "barButtonBack:") newBackButton.setTitleTextAttributes(attributes, forState: .Normal) navigationItem.leftBarButtonItem = newBackButton – Vibha Singh Jun 02 '16 at 09:39
  • Checkout: https://stackoverflow.com/a/28347428/469614 – Vexy Apr 06 '18 at 11:32

1 Answers1

2

Swift:

UIBarButtonItem.appearance().setTitleTextAttributes([NSAttributedString.Key.font: UIFont(name: "Poppins-Regular", size: 16)!,NSAttributedString.Key.foregroundColor:.red], for: .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];
Bhadresh Mulsaniya
  • 2,610
  • 1
  • 12
  • 25