Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a custom font in iOS tab bar

I'm using the font awesome resource for the UI of my iPhone application : FontAwesome

I have used it within my app screens like follows :

Phone.font = [UIFont fontWithName:kFontAwesomeFamilyName size:40];
Phone.text = [NSString fontAwesomeIconStringForIconIdentifier:@"fa-phone"];

But now I want to use it in the tab bar items of my tab bar controller i.e I want to set the icons of the tab bar to font awesome elements. How can this be done?

like image 812
MattTheHack Avatar asked Feb 19 '14 16:02

MattTheHack


People also ask

How do I add custom fonts to my iPhone?

You can download fonts from the App Store app , then use them in documents you create on iPhone. After you download an app containing fonts from the App Store, open the app to install the fonts. To manage installed fonts, go to Settings > General, then tap Fonts.

How do I add fonts to info plist?

To do this, add the key "Fonts provided by application" to Info. plist (the raw key name is UIAppFonts ). Xcode creates an array value for the key; add the name of the font file as an item of the array. Be sure to include the file extension as part of the name.


3 Answers

As per: How to change the Color of text in UITabBarItem in iOS 5

It looks like the solution may be sending the message to the appearance proxy, instead of one item:

[[UITabBarItem appearance] setTitleTextAttributes:@{
                                                    NSFontAttributeName:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f]
                                                    } forState:UIControlStateNormal];

here is some more reference

how-to-change-the-color-of-text-in-uitabbaritem-in-ios-5

ios5-tabbar-fonts-and-color

like image 85
5 revs, 3 users 67% Avatar answered Oct 04 '22 13:10

5 revs, 3 users 67%


Swift version:

    UITabBarItem.appearance().setTitleTextAttributes(
            [NSFontAttributeName: UIFont(name:"Ubuntu", size:11)!, 
                NSForegroundColorAttributeName: UIColor(rgb: 0x929292)], 
            forState: .Normal)
like image 9
superarts.org Avatar answered Oct 04 '22 12:10

superarts.org


Swift 3

UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name:"Latio-Regular", size:14)!, NSForegroundColorAttributeName: UIColor.white], for: .normal)
like image 7
4 revs, 3 users 77% Avatar answered Oct 04 '22 11:10

4 revs, 3 users 77%