16

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?

MattTheHack
  • 1,354
  • 7
  • 28
  • 48

8 Answers8

30

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

Community
  • 1
  • 1
Pawan Rai
  • 3,434
  • 4
  • 32
  • 42
9

Swift version:

    UITabBarItem.appearance().setTitleTextAttributes(
            [NSFontAttributeName: UIFont(name:"Ubuntu", size:11)!, 
                NSForegroundColorAttributeName: UIColor(rgb: 0x929292)], 
            forState: .Normal)
superarts.org
  • 7,009
  • 1
  • 58
  • 44
7

Swift 3

UITabBarItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name:"Latio-Regular", size:14)!, NSForegroundColorAttributeName: UIColor.white], for: .normal)
Niklas
  • 1,322
  • 14
  • 11
4

Swift 4

This is an example how it works with Swift 4:

UITabBarItem.appearance().setTitleTextAttributes([NSAttributedStringKey.font: UIFont(name: "Renner-it-Book", size: 10)!, NSAttributedStringKey.foregroundColor: UIColor.gray], for: .normal)
Roland T.
  • 841
  • 9
  • 16
3

I was not able to change the font using the accepted answer. This is what I used later in my

didFinishLaunchingWithOptions
method of AppDelegate:
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    UITabBar *tabBar = tabBarController.tabBar;
    UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
    UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];

    [tabBarItem1 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17 weight:UIFontWeightBold], NSFontAttributeName, nil] forState:UIControlStateSelected];

    [tabBarItem2 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17 weight:UIFontWeightBold], NSFontAttributeName, nil] forState:UIControlStateSelected];

    [tabBarItem1 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17 weight:UIFontWeightBold], NSFontAttributeName, nil] forState:UIControlStateNormal];

    [tabBarItem2 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17 weight:UIFontWeightBold], NSFontAttributeName, nil] forState:UIControlStateNormal];

More information here: http://www.appcoda.com/ios-programming-how-to-customize-tab-bar-background-appearance/

kerry
  • 2,362
  • 20
  • 33
2

Try this code:

[[UITabBarItem appearance] setTitleTextAttributes: @{NSForegroundColorAttributeName: TAB_BAR_TEXT_NORMAL_COLOR, NSFontAttributeName: [UIFont fontWithName:CUSTOM_FONT_NAME size:TAB_BAR_FONT_SIZE]} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor], NSFontAttributeName: [UIFont fontWithName:CUSTOM_FONT_NAME size:TAB_BAR_FONT_SIZE]} forState:UIControlStateSelected];
Sujith Thankachan
  • 3,508
  • 2
  • 20
  • 25
2

Since in iOS7 UITextAttributeFont is deprecated, use NSFontAttributeName

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"your_font_name" size:20.0f], NSFontAttributeName, nil] forState:UIControlStateNormal];
itsji10dra
  • 4,603
  • 3
  • 39
  • 59
andreacipriani
  • 2,519
  • 26
  • 23
1

use this it works perfectly...

UIView *iv = [[UIView alloc] initWithFrame:CGRectMake(0,0,230.0,80.0)];
UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 230, 80)];
lbl.textColor = [UIColor whiteColor];
lbl.font = [UIFont fontWithName:@"Ubuntu" size:18.0f];
lbl.textAlignment = NSTextAlignmentCenter;
lbl.text = [NSString stringWithFormat:@"%lu Store Found",(unsigned long)arrOfferList.count];
[iv addSubview:lbl];
self.tabBarController.navigationItem.titleView = iv;
Harshit
  • 184
  • 9