Customizing UITabBar to display a different bg

Discussion in 'iOS Programming' started by marcolara, Aug 15, 2008.

  1. marcolara macrumors newbie

    Joined:
    Aug 15, 2008
    #1
    I looked all over the forum and googled without any success on this matter. I want to customize a UITabBar to display an image background instead of the dark gray background provided by the SDK. Is there a way for me to do this?

    I tried creating a category for UITabBar and overwrite the drawRect method but this also has no effect since I don't even see in the debugger the UITabBar calling my method.

    I'm doing most of it programmatically in my code and as far as I understand the UITabBar is directly attached to a UITabBarController, however the UITabBarItem objects are inside the UIViewController... is it possible that the change needs to happen in the UIViewController and not the UITabBar itself?

    I've already spent over a day on this matter so it's time for me to ask the community for help so any suggestions, code snipped or comments will be highly appreciated.

    Regards,
    ML
     
  2. mccannmarc macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #2
    have you tried subclassing it and implementing your own drawrect method that way?
     
  3. marcolara thread starter macrumors newbie

    Joined:
    Aug 15, 2008
    #3
    Yes I did subclass the object, however, I really don't know how to implement it since the UITabBar is part of the UITabBarController itself. Is there a clear example as to how to use the UITabBar and add the ViewControllers to it without using the UITabBarController?

    -ML
     
  4. marcolara thread starter macrumors newbie

    Joined:
    Aug 15, 2008
    #4
    Problem solved!

    I was able to get some help from a great developer. It was a simple implementation:

    Code:
    [[tabBarController tabBar] addSubview:view];
    I'm passing an UIImageView as the view so I can get a customized background for my tab views.

    --- Thanks Danielle C. for the tip! :)
     
  5. jchildress macrumors member

    Joined:
    Jul 9, 2008
    #5
    Is this background the size of the entire screen? or just a background for the tabBar at the bottom of the screen (360 x 40~ pixels)?

    If the background is the entire screen, do you see it load immediatly as the app starts up? Or does it not appear until the tabBar's initial view is finished loading? Is the background always there, just drawn behind the current UIViewController?

    Sorry for so many questions, but I think that you might be trying something that I've been trying to do for awhile now.
     
  6. marcolara thread starter macrumors newbie

    Joined:
    Aug 15, 2008
    #6
    Nope. This is just to change/display an image behind the TabBar itself. The UIImageView is attached before the screen is rendered.
     
  7. holtmann macrumors newbie

    Joined:
    Sep 24, 2008
    #7
    This does not work for me:

    1. [[tabBarController tabBar] addSubview:view]; - tabBar is an undefined method for an UIViewController
    2. If I access the UITabBar through an IBOutlet set in InterfaceBuilder and do
    then
    [tabbar addSubView:myView] the View is added not as a background. The active item e.g. is still visible, but the inactive TabBarItems are invisible.

    Any hints how to do this properly?

    Best,

    Hendrik

     
  8. Isorinu' macrumors newbie

    Joined:
    Oct 16, 2008
    #8
    can somebody give an example how to change the color of the UITabBar? or to put a background image?

    I have a UITabBarController made programatically and i add ViewControllers to it..i tried the method mentioned above but it doesn;t work.. please help..i want to change the black color to lightGrayColor..
    Thank you in advance
     
  9. priyank.ranka macrumors member

    Joined:
    Jun 11, 2008
    #9
    I also have the same issue i want to change dark gray to green... does anyone knows please do let me know...Many many thanx in advance
     

Share This Page