Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7160615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:25:40+00:00 2026-05-28T13:25:40+00:00

I’m trying to programmatically set the background image for a tabbar in my app.

  • 0

I’m trying to programmatically set the background image for a tabbar in my app. My code is as follows:

RootViewController.h

IBOutlet UITabBar *mainTabBar;
    IBOutlet UITabBarItem *settingsBarItem;
    IBOutlet UITabBarItem *infoBarItem;
    IBOutlet UITabBarItem *aboutBarItem;

RootViewController.m

-(void)viewDidLoad {

    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"smallMenuBackground.png"]];    
    [mainTabBar insertSubview:imageView atIndex:0];
    [imageView release];

    [super viewDidLoad];
}

This is not working for me.

UPDATE

UPDATE 23rd January 2012

Ok, I’ve made a bit of progress. This only stopped working since I upgraded to Xcode 4.2 and IOS5. I managed to get it back using the options in Interface Builder, but now it only works for IOS5. Ideally I would have liked to get working programatically but I’ll settle for the IB solution for now.

I just can’t seem to get it working for any previous releases.

NOTE: my TabBar is only on my RootViewController, which is the main screen of my app.

Ideally, if I could get the code working that Nithin suggested, that would be great:

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabBG.png"]];

if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {
    //iOS 5
    [self.tabBarController.tabBar insertSubview:imageView atIndex:1];
}
else {
    //iOS 4.whatever and below
    [self.tabBarController.tabBar insertSubview:imageView atIndex:0];
}

[imageView release];

Any help would be appreciated.

Regards,
Stephen

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:25:40+00:00Added an answer on May 28, 2026 at 1:25 pm

    You can use custom class for UITabBarController & override your tabBarController. There you can set your required buttons & their actions with image.

    This is how your custom tab bar controller class can be look like:

    // CustomTabBarController.h

    #import <UIKit/UIKit.h>
    
    @interface CustomTabBarController : UITabBarController {
        UIButton *settingsButton;
        UIButton *infoButton;
        UIButton *aboutUsButton;
    }
    
    @property (nonatomic, retain) UIButton *settingsButton;
    @property (nonatomic, retain) UIButton *infoButton;
    @property (nonatomic, retain) UIButton *aboutUsButton;
    
    -(void) addCustomElements;
    -(void) selectTab:(int)tabID;
    
    @end
    

    // CustomTabBarController.m

    #import "CustomTabBarController.h"
    
    @implementation CustomTabBarController
    
    @synthesize settingsButton, infoButton, aboutUsButton;
    
    - (void)viewDidAppear:(BOOL)animated {
        [super viewDidAppear:animated];
    
    
    }
    -(void)viewDidLoad
    {
        [super viewDidLoad];
        [self addCustomElements];
    }
    
    -(void)addCustomElements
    {
        // Background
        UIImageView* bgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tabBarBackground.png"]] autorelease];
        bgView.frame = CGRectMake(0, 420, 320, 60);
        [self.view addSubview:bgView];
    
        // Initialise our two images
        UIImage *btnImage = [UIImage imageNamed:@"settings.png"];
        UIImage *btnImageSelected = [UIImage imageNamed:@"settingsSelected.png"];
    
        self.settingsButton = [UIButton buttonWithType:UIButtonTypeCustom]; //Setup the button
        settingsButton.frame = CGRectMake(10, 426, 100, 54); // Set the frame (size and position) of the button)
        [settingsButton setBackgroundImage:btnImage forState:UIControlStateNormal]; // Set the image for the normal state of the button
        [settingsButton setBackgroundImage:btnImageSelected forState:UIControlStateHighlighted]; // Set the image for the selected state of the button
        [settingsButton setBackgroundImage:btnImageSelected forState:UIControlStateSelected]; // Set the image for the selected state of the button
        [settingsButton setBackgroundImage:btnImageSelected forState:UIControlStateDisabled];
        [settingsButton setImage:btnImageSelected forState:(UIControlStateHighlighted|UIControlStateSelected)];
        [settingsButton setTag:101]; // Assign the button a "tag" so when our "click" event is called we know which button was pressed.
        [settingsButton setSelected:true]; // Set this button as selected (we will select the others to false as we only want Tab 1 to be selected initially
    
        // Now we repeat the process for the other buttons
        btnImage = [UIImage imageNamed:@"info.png"];
        btnImageSelected = [UIImage imageNamed:@"infoSelected.png"];
        self.infoButton = [UIButton buttonWithType:UIButtonTypeCustom];
        infoButton.frame = CGRectMake(110, 426, 100, 54);
        [infoButton setBackgroundImage:btnImage forState:UIControlStateNormal];
        [infoButton setBackgroundImage:btnImageSelected forState:UIControlStateSelected];
        [infoButton setBackgroundImage:btnImageSelected forState:UIControlStateHighlighted];
        [infoButton setImage:btnImageSelected forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
        [infoButton setTag:102];
    
        btnImage = [UIImage imageNamed:@"aboutUs.png"];
        btnImageSelected = [UIImage imageNamed:@"aboutUsSelected.png"];
        self.aboutUsButton = [UIButton buttonWithType:UIButtonTypeCustom];
        aboutUsButton.frame = CGRectMake(210, 426, 100, 54);
        [aboutUsButton setBackgroundImage:btnImage forState:UIControlStateNormal];
        [aboutUsButton setBackgroundImage:btnImageSelected forState:UIControlStateSelected];
        [aboutUsButton setBackgroundImage:btnImageSelected forState:UIControlStateHighlighted];
        [aboutUsButton setImage:btnImageSelected forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
        [aboutUsButton setTag:103];
    
        // Add my new buttons to the view
        [self.view addSubview:settingsButton];
        [self.view addSubview:infoButton];
        [self.view addSubview:aboutUsButton];
    
        // Setup event handlers so that the buttonClicked method will respond to the touch up inside event.
        [settingsButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [infoButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
        [aboutUsButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    - (void)buttonClicked:(id)sender
    {
        int tagNum = [sender tag];
        [self selectTab:tagNum];
    }
    
    - (void)selectTab:(int)tabID
    {
        switch(tabID)
        {
            case 101:
                [settingsButton setSelected:true];
                [infoButton setSelected:false];
                [aboutUsButton setSelected:false];
                break;
            case 102:
                [settingsButton setSelected:false];
                [infoButton setSelected:true];
                [aboutUsButton setSelected:false];
                break;
            case 103:
                [settingsButton setSelected:false];
                [infoButton setSelected:false];
                [aboutUsButton setSelected:true];
                break;
        }   
        self.selectedIndex = tabID;
    }
    
    - (void)dealloc {
        [settingsButton release];
        [infoButton release];
        [aboutUsButton release];
    
        [super dealloc];
    }
    
    @end
    

    Hope this will help you a lot.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am writing an app with both english and french support. The app requests

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.