2014-03-13 44 views
0

我在tabbar中添加圖像。尺寸爲49px。添加工作正常。但佈局有一個問題。所有tabbar項目圖像的頂部部分都不在tabbar的框架中,並且存在空白空間。Tabbar項目圖像問題

如何解決這個問題?

這是我創建的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]; 
     //[email protected]""; 



     uploadVC = [[FilesView alloc] initWithNibName:@"FilesView_iPhone" bundle:nil]; 
     uploadNavBar=[[UINavigationController alloc]initWithRootViewController:uploadVC]; 
     //[email protected]""; 

     searchVC = [[PhotosView alloc] initWithNibName:@"PhotosView_iPhone" bundle:nil]; 
     searchNavBar=[[UINavigationController alloc]initWithRootViewController:searchVC]; 
     //[email protected]""; 

     nearbyVC = [[AttendeesView alloc] initWithNibName:@"AttendeesView_iPhone" bundle:nil]; 
     nearbyNavBar=[[UINavigationController alloc]initWithRootViewController:nearbyVC]; 
     //[email protected]""; 



     [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; 

和設置的TabBar項這樣的 -

-(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

回答

0

試試這個..我有同樣的問題,幾天回來,而這代碼修復了它。

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]; 

希望這將幫助你

+0

沒有同樣的問題occurs..there是每一個標籤欄項目的下方空間 –