当我添加 UITabBar 背景图片时,高度会自动增加

when i am adding in UITabBar background image then height increase automatically

我正在添加 UITabBar 控制器,但问题是当我设置背景图像时它的底部是黑色 space 并且当我删除背景图像时它工作正常。 我正在添加应用程序委托

  -(void)gotoLoginStoryBoard
{
    UIStoryboard *storyboard ;
        storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *login = [storyboard instantiateInitialViewController];
    recentsViewController = [[RecentsViewController alloc]
                             initWithStyle:UITableViewStylePlain];
    recentsViewController.phoneCallDelegate = self;
    UINavigationController *recentsViewCtrl = [[[UINavigationController alloc]
                                                initWithRootViewController:
                                                recentsViewController]
                                               autorelease];
    recentsViewCtrl.navigationBar.barStyle = UIBarStyleBlackOpaque;
    [recentsViewController release];
    phoneViewController = [[[PhoneViewController alloc]
                            initWithNibName:nil bundle:nil] autorelease];
    phoneViewController.phoneCallDelegate = self;
    ContactViewController *contactsViewCtrl = [[[ContactViewController alloc]
                                                init] autorelease];
    contactsViewCtrl.phoneCallDelegate = self;
    VoicemailController *voicemailController = [[VoicemailController alloc]
                                                initWithStyle:UITableViewStyleGrouped];
    voicemailController.phoneCallDelegate = self;
    UINavigationController *voicemailNavCtrl = [[[UINavigationController alloc]
                                                 initWithRootViewController:
                                                 voicemailController]
                                                autorelease];
    voicemailNavCtrl.navigationBar.barStyle = UIBarStyleBlackOpaque;
    [voicemailController release];
    tabBarController = [[UITabBarController alloc] init];
    tabBarController.viewControllers = [NSArray arrayWithObjects:
                                        /*favoritesViewCtrl,*/ login,
                                        phoneViewController, contactsViewCtrl, nil];
    tabBarController.selectedIndex = 0;
     [[UITabBar appearance] setTintColor:[UIColor whiteColor]];
    [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabbarimage.png"]];
    [[[self.tabBarController.viewControllers objectAtIndex:1] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:@"fill3Copy.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"pathCopy4.png"]];
    [[[self.tabBarController.viewControllers objectAtIndex:1] tabBarItem]setTitle:@"Contact"];
    [[[self.tabBarController.viewControllers objectAtIndex:2] tabBarItem]setFinishedSelectedImage:[UIImage imageNamed:@"fill3Copy3.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"pathCopy5.png"]];
    [[[self.tabBarController.viewControllers objectAtIndex:2] tabBarItem]setTitle:@"Group"];
   [[UITabBar appearance] setBackgroundColor:[UIColor blackColor ]];
    [self.window setRootViewController:tabBarController];

}

首先检查你的图像大小。

from apple documentation the maximum size of a picture on the TabBar are 30x30 (60x60 for the retina display).

我认为如果不像 UIimageview 那样拉伸图像,就不可能占据 TabBar 的整个高度。所以,根据我的说法,最好的解决方案是使用 imageInset 将图像置于 TabBar 的中心。

tabBarItem.imageInsets = UIEdgeInsetsMake(0, -10, -6, -10);

                        OR


tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

设置 Imageinsect 直到图像适合标签栏控制器。

有关更多详细信息,请查看下面的 Apple 文档 link。

Icon and Image Sizes

希望对你有所帮助

我在上诉中漏掉了这一行。

MelpHomeViewController *melpHome = (MelpHomeViewController *)[storyboard instantiateViewControllerWithIdentifier:@"homeController"];