UITabBarItem with custom title color and images

16,947

Solution 1

And I'm one of the people that says that it really doesn't work. You have to reimplement the whole functionality in a Custom UIViewController which acts as a UITabBar replacement.

Just like Twitter for iPhone or Tweetbot did.

enter image description here

Solution 2

In iOS 5.0 and newer, you can Customize UITabBar's Appearance by changing the tint color, the background image and the selection indicator, to make them look the way you like.

You can also customize the individual UITabBarItems, by invoking the setFinishedSelectedImage:withFinishedUnselectedImage: method with finished selected and unselected images as parameters.

Alternatively, modifying the appearance proxy of UITabBar allows you to change the aspect of all its instances.

Solution 3

Totally not customizable. You either use whatever Apple provided to you (mask images for shapes and titles) or you roll your own.

One way that has worked for me is subclassing the tab bar. Use your own subviews to make the tab bar look they way you want it to. For example: use a background image and dynamically overlay that with buttons for each of the tabBarItems.

This way you can still configure the tab bar in Interface Builder and you get the switching of the tab bar content for free. At the same time the tab bar will look the way you want.

Share:
16,947
Arthur Neves
Author by

Arthur Neves

Software Developer @GitHub

Updated on August 07, 2022

Comments

  • Arthur Neves
    Arthur Neves almost 2 years

    I`m trying to customize my TabBar in xcode,ios, however I just found ppl saying that this is not customizable! also, i did find some sort of solutions, but none of them are working for me.

    Pretty much I want to change the UITabBarItem title(text) color, and also change the 2 images inside it, the normal one and the selected one!

    I tried to iterate inside my UITabBar subviews to see if I find something, but any success:

    for (UIView *view in [self.tabBarController tabBar].subviews) 
    {
        NSLog(@"Class: %@",[view class]);
    
    }
    

    the output of this was:

    2011-05-18 18:15:24.031 EventApp[52235:207] Class: UIImageView
    2011-05-18 18:15:24.032 EventApp[52235:207] Class: UITabBarButton
    2011-05-18 18:15:24.032 EventApp[52235:207] Class: UITabBarButton
    2011-05-18 18:15:24.033 EventApp[52235:207] Class: UITabBarButton
    2011-05-18 18:15:24.033 EventApp[52235:207] Class: UITabBarButton
    2011-05-18 18:15:24.034 EventApp[52235:207] Class: UITabBarButton
    

    and I cannot import that UITabBarButton obj to work with it!

    Some solution for that?! also I posted some links bellow which I`ve looked, but didnt work!

    Custom UITabBarItem Image/Title on iPhone

    changing text color of uitabbaritem

    EDIT What I wanna do is somethink like the follow: enter image description here

  • Arthur Neves
    Arthur Neves about 13 years
    Really!??! I posted what I want to do! any easy solution?! I`ve already changed the background color to an image! just missing the labels and buttons now!
  • Arthur Neves
    Arthur Neves about 13 years
    Could U post the code, I mean, at least the drawRect! or U didnt implement it?!
  • Jano
    Jano about 13 years
    This is right. From idevrecipes.com/2010/12/16/raised-center-tab-bar-button A UITabBar contains an array of UITabBarItems, which inherit from UIBarItem. But unlike UIBarButtonItem that also inherits from UIBarItem, there is no API to create a UITabBarItem with a customView. Either you overlap a button or you roll your own component fresh.
  • Joris Kluivers
    Joris Kluivers about 13 years
    No, I'm not using drawRect. I use a 320x49 image as the background, this covers all existing tabs. Then I use my own UIControls (made up of several CALayers for animation effects) for my own buttons. I only reuse (as in subclass) the tab bar so I can configure it in Interface Builder, and still get to use a UITabBarController. Otherwise its just like a custom control that just happens to look like a tab bar.