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!
Asked
Active
Viewed 1,003 times
0

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 Answers
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
-
1
-
-
1UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont.fontNamesForFamilyName("Futura-Medium"), NSForegroundColorAttributeName:UIColor.whiteColor()], forState: UIControlState.Normal) – Vibha Singh Jun 02 '16 at 09:50
-
-