How to change image of UItabbar icon?

I am working on an application and want to customize the UItabbar icon image.

I have an image called about.png of this image that I want to set as the image of the left icon of my UItabbar application. How can i do this?

+3
source share
5 answers

k you use this code and used your own images, not the images embedded in it ...

- (id)init {
UIImage* anImage = [UIImage imageNamed:@"newspaper.png"];
UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"News" image:anImage tag:0];
self.tabBarItem = theItem;
[theItem release];
return self;  }

newspaper.png is my own image in the tab bar ...

k fine now this will be enough for your problem ...

+3
source

If you want to change the image for a UITabbarItem , you can use its instance method

- (id)initWithTitle:(NSString  *)title image:(UIImage  *)image tag:(NSInteger)tag
0

init() viewController, .

- (id)init {

if (self = [super initWithNibName:@"Search" bundle:nil]) {
    UIImage* tabImage = [UIImage imageNamed:@"search.png"];
    UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"Search" image:tabImage tag:0];
    self.tabBarItem = theItem;
    [theItem release];
}
return self;
}  
0

( IB)

: -

UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"News" image:anImage tag:0];

use it or if you are doing it visually: - Click on the icon of a specific tab in IB and select the setting and icon and specify the name of a specific icon file.

Let this solve your problem ...

0
source

You can change that. in the delegate method of the scoreboard controller

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

{
    if([tabBarController selectedIndex] == 0)
    {
        [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
    }    
}

through this you can change your tabbaritem image.

Or you can use init (or ViewWillAppear) controllers directly in your view, for example

        [viewController.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"selected.png"]withFinishedUnselectedImage:[UIImage imageNamed:@"unselect.png"]];
0
source

All Articles