Tina
Tina

Reputation: 31

Icon images not showing on tabbar in iOS 7?

I am going one page to another and that another page have UITabbarcontroller.

That have:

  1. Home 2. CutPipe 3. Fitting 4. Flange 5. Setting

Now these five names are showing but I have these five icon images that are not showing and screen showing black and If I do clearcolor then screen showing grey.

I also want how to control height of UITabbarcontroller.

My problem is that the icon images not showing on tabbar.

I also add background image on UITabbar and add on icon images also. But it is not showing.

Here is my code.

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

// Retrieve the last view name
NSInteger firstValue = [[NSUserDefaults standardUserDefaults] integerForKey:@"firstValue"];

if (firstValue == 10) {
    [self method_Tabs];
}
}


-(void)method_Tabs{


// Set the name of the view
[[NSUserDefaults standardUserDefaults] setInteger:11 forKey:@"firstValue"];




  my_Tabbar = [[UITabBarController alloc] init]; // how to control height of my_Tabbar?
 // my_Tabbar.view.frame=CGRectMake(0, 100, 320,30);   // is there any way to control this
// my_Tabbar.view.backgroundColor = [UIColor redColor];

  my_Tabbar.tabBar.barTintColor = [UIColor clearColor];

 self.tabBarController.tabBar.translucent = false;

 // this will give selected icons and text your apps tint color
 my_Tabbar.tabBar.tintColor = [UIColor blueColor];

 [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:13.0f],
                                                    NSForegroundColorAttributeName :    [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:1]
                                                    } forState:UIControlStateNormal];




 Homepage_AdvancePipeOffset  *VC_1 = [[Homepage_AdvancePipeOffset alloc]  initWithNibName:nil bundle:nil];
Apo_Cut_Pipe                *VC_2 = [[Apo_Cut_Pipe alloc] initWithNibName:nil bundle:nil];
Apo_Fitting                 *VC_3 = [[Apo_Fitting alloc] initWithNibName:nil bundle:nil];
Apo_Flange                  *VC_4 = [[Apo_Flange alloc] initWithNibName:nil bundle:nil];
Apo_Setting                 *VC_5 = [[Apo_Setting alloc] initWithNibName:nil bundle:nil];




UINavigationController *rvc_Home     = [[UINavigationController alloc] initWithRootViewController: VC_1];
UINavigationController *rvc_CutPipe  = [[UINavigationController alloc] initWithRootViewController: VC_2];
UINavigationController *rvc_Fitting  = [[UINavigationController alloc] initWithRootViewController: VC_3];
UINavigationController *rvc_Flange   = [[UINavigationController alloc] initWithRootViewController: VC_4];
UINavigationController *rvc_Setting  = [[UINavigationController alloc] initWithRootViewController: VC_5];


rvc_Home.tabBarItem.image    =[UIImage imageNamed:@"home.png"];
rvc_CutPipe.tabBarItem.image =[UIImage imageNamed:@"icon_cut_pipe.png"];
rvc_Fitting.tabBarItem.image =[UIImage imageNamed:@"icon_fittings.png"];
rvc_Flange.tabBarItem.image  =[UIImage imageNamed:@"icon_flanges.png"];
rvc_Setting.tabBarItem.image =[UIImage imageNamed:@"icon_settings.png"];


rvc_Home.tabBarItem.title=@"Home";
VC_1.tabBarController.tabBar.tag = 1;

rvc_CutPipe.tabBarItem.title=@"CutPipe";
VC_2.tabBarController.tabBar.tag = 2;

rvc_Fitting.tabBarItem.title=@"Fitting";
VC_3.tabBarController.tabBar.tag = 3;

rvc_Flange.tabBarItem.title=@"Flange";
 VC_4.tabBarController.tabBar.tag = 4;

 rvc_Setting.tabBarItem.title=@"Setting";
 VC_5.tabBarController.tabBar.tag = 5;


NSArray* controllers = [NSArray arrayWithObjects: rvc_Home,rvc_CutPipe,rvc_Fitting,rvc_Flange, rvc_Setting, nil];


[my_Tabbar setViewControllers: controllers animated:NO];
[self.view addSubview:my_Tabbar.view];
my_Tabbar.selectedIndex=4;
[self.navigationController pushViewController:my_Tabbar animated:YES];

}

Upvotes: 1

Views: 7532

Answers (6)

Binoy jose
Binoy jose

Reputation: 471

Please try this

[UITabBarItem setImage:[[UIImage imageNamed:@"tab_03"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

[UITabBarItem setSelectedImage:[[UIImage imageNamed:@"tab_03_h"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];

Upvotes: 0

Pawan Rai
Pawan Rai

Reputation: 3444

I will suggest you to subclass your UITabBarController and set your custom images in tabBarItem in viewDidLoad method .

Check this code:

- (void)viewDidLoad
{
[super viewDidLoad];

UITabBar *tabBar = self.tabBar;

UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];

[item0 setFinishedSelectedImage:[UIImage imageNamed:@"search-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"search-icon"]];


[item0 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[item1 setFinishedSelectedImage:[UIImage imageNamed:@"tag-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"tag-icon"]];
[item1 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[item2 setFinishedSelectedImage:[UIImage imageNamed:@"add-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"add-icon"]];
[item2 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[item3 setFinishedSelectedImage:[UIImage imageNamed:@"profile-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"profile-icon"]];
[item3 setImageInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

self.selectedIndex=2;
}

It looks some thing like this to me:

custom tab bar

Upvotes: 3

Pandey_Laxman
Pandey_Laxman

Reputation: 3908

Try using

VC_1.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"Home" image:[UIImage imageNamed:@"HomeOn.png"] selectedImage:[UIImage imageNamed:@"HomeOf.png"]];

Or

VC_1.tabBarItem=[[UITabBarItem alloc]initWithTitle:@"Home" image:[UIImage imageNamed:@"home"] tag:1];

Upvotes: 1

Sujith Thankachan
Sujith Thankachan

Reputation: 3506

Try this for setting tab bar items:

rvc_Home.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Home" image:[[UIImage imageNamed:@"home.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[UIImage imageNamed:HOME_SELECTED_IMAGE]];

EDIT

Add the code below in your tab implementation:

[[yourTabBarController tabBar] setBackgroundImage:[UIImage imageNamed:@"tabBarBg.png"]];
[[yourTabBarController tabBar] setSelectionIndicatorImage:[UIImage imageNamed:@"selectionImage.png"]];

[[yourTabBarController tabBar] setTintColor:[UIColor whiteColor]];

Upvotes: 1

Sandeep Agrawal
Sandeep Agrawal

Reputation: 425

 self.tabBarController = [[UITabBarController alloc] init];
   self.tabBarController.delegate = self;
   self.tabBarController.selectedIndex = 0;
   UITabBar *tabBar = self.tabBarController.tabBar;
   UITabBarItem *item0 = [tabBar.items objectAtIndex:0];    
    if(IsRunningTallPhone())
        self.tabBarController.tabBar.frame = CGRectMake(0, 430+88, 320, 62);
    else
        self.tabBarController.tabBar.frame = CGRectMake(0, 430, 320, 62);  
    UIImage *selectedImageTab0 =[UIImage imageNamed:@"home_btn_selected.png"];
    UIImage *unselectedTab0 =[UIImage imageNamed:@"home_btn.png"];       
    [item0 setFinishedSelectedImage:selectedImageTab0 withFinishedUnselectedImage:unselectedTab0];

Upvotes: 0

Samkit Jain
Samkit Jain

Reputation: 2523

Try using :

VC_1.tabBarItem.image    =[UIImage imageNamed:@"home.png"];
VC_2.tabBarItem.image =[UIImage imageNamed:@"icon_cut_pipe.png"];
VC_3.tabBarItem.image =[UIImage imageNamed:@"icon_fittings.png"];
VC_4.tabBarItem.image  =[UIImage imageNamed:@"icon_flanges.png"];
VC_5.tabBarItem.image =[UIImage imageNamed:@"icon_settings.png"];

Upvotes: 0

Related Questions