Question

I am adding images in tabbar. The iamge size is 49px. Adding is working fine. But the layout having an issue. all tabbar item images' top part is out of tabbar's frame, and there is ablank space down.

How to fix this ?

This is how I create Tabbar

        localViewControllersArray = [[NSMutableArray alloc] initWithCapacity:3];


        myhomeVC = [[EventListView alloc] initWithNibName:@"EventListView_iPhone" bundle:nil];
        homeNavBar=[[UINavigationController alloc]initWithRootViewController:myhomeVC];
        homeNavBar.tabBarItem.title=nil;



        groupVC = [[ItineryView alloc] initWithNibName:@"ItineryView_iPhone" bundle:nil];
        groupNavBar=[[UINavigationController alloc]initWithRootViewController:groupVC];
        //groupNavBar.tabBarItem.title=@"";



        uploadVC = [[FilesView alloc] initWithNibName:@"FilesView_iPhone" bundle:nil];
        uploadNavBar=[[UINavigationController alloc]initWithRootViewController:uploadVC];
        //uploadNavBar.tabBarItem.title=@"";

        searchVC = [[PhotosView alloc] initWithNibName:@"PhotosView_iPhone" bundle:nil];
        searchNavBar=[[UINavigationController alloc]initWithRootViewController:searchVC];
        //searchNavBar.tabBarItem.title=@"";

        nearbyVC = [[AttendeesView alloc] initWithNibName:@"AttendeesView_iPhone" bundle:nil];
        nearbyNavBar=[[UINavigationController alloc]initWithRootViewController:nearbyVC];
        //nearbyNavBar.tabBarItem.title=@"";



        [localViewControllersArray addObject:homeNavBar];
        [localViewControllersArray addObject:groupNavBar];
        [localViewControllersArray addObject:uploadNavBar];
        [localViewControllersArray addObject:searchNavBar];
        [localViewControllersArray addObject:nearbyNavBar];



        appDelegate.tabBarController.viewControllers = localViewControllersArray;
        [self.parentViewController.view setHidden:YES];

        appDelegate.window.rootViewController = appDelegate.tabBarController;

and setting tabbar item like this -

  -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
   {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
     if (self) {
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

        [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"navHomeHL.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"navHome.png"]];

       } }

       return self;
       }

enter image description here

Was it helpful?

Solution

Try This.. I got same issue couple of days back and this code fixed it.

UIViewController *viewController1, *viewController2,*viewController3;   
viewController1 = [[ViewController alloc] init];  
viewController2 = [[FormStatusViewController alloc] initWithNibName:@"FormStatusViewController" bundle:nil];   
viewController3 = [[DocumentsViewController alloc] init];  

UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:viewController1];   
UINavigationController *nav1 =[[UINavigationController alloc] initWithRootViewController:viewController2];
UINavigationController *nav2 =[[UINavigationController alloc] initWithRootViewController:viewController3];

nav.navigationBarHidden=YES;
nav1.navigationBarHidden=YES;
nav2.navigationBarHidden=YES;

NSArray *viewsArray = [[NSArray alloc] initWithObjects:nav,nav1,nav2, nil];
self.formTabBar= [[UITabBarController alloc] init];
[self.formTabBar setViewControllers:viewsArray];

UITabBar *tabBar = self.formTabBar.tabBar;
UITabBarItem *tabBarItem1 = [tabBar.items objectAtIndex:0];
UITabBarItem *tabBarItem2 = [tabBar.items objectAtIndex:1];
UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];

tabBarItem1.title = @"FORM";
tabBarItem2.title = @"STATUS";
tabBarItem3.title = @"DOCUMENTS";

UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg.png"]
                          resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UITabBar appearance] setBackgroundImage:tabBackground];

if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
    [tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"form.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"form_h.png"]];
    [tabBarItem2 setFinishedSelectedImage:[UIImage imageNamed:@"status.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"status_h.png"]];
    [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"documents.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"documents_h.png"]];
} else {
    tabBarItem1.selectedImage = [[UIImage imageNamed:@"form_h.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
    tabBarItem1.image = [[UIImage imageNamed:@"form.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];

    tabBarItem2.selectedImage = [[UIImage imageNamed:@"status_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
    tabBarItem2.image = [[UIImage imageNamed:@"status.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];

    tabBarItem3.selectedImage = [[UIImage imageNamed:@"documents_h.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];
    tabBarItem3.image = [[UIImage imageNamed:@"documents.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal ];


}
[[UITabBar appearance] setSelectionIndicatorImage:
[UIImage imageNamed:@"tab_select_indicator.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   [UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateNormal];

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                   [UIColor whiteColor], UITextAttributeTextColor,nil] forState:UIControlStateHighlighted];

Hope this will help you

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top