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

时间:2016-01-26 09:07:02

标签: ios objective-c ios7

我正在添加UITabBar控制器,但问题是,当我设置背景图像时,它从底部的黑色空间,当我删除背景图像时,它的工作正常。  我正在添加app delegate

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

}

 I have added screen shots from down site its black screen

2 个答案:

答案 0 :(得分:0)

首先检查你的影像大小。

  

从Apple文档中TabBar上图片的最大尺寸   是30x30(视网膜显示器为60x60)。

我认为如果没有像UIimageview这样的图像,就不可能占用TabBar的整个高度。所以,据我所知,最好的解决方案是使用imageInset将图像置于TabBar中。

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

                        OR


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

将Imageinsect设置为图像适合tabbar控制器。

详细信息请查看以下链接的Apple文档。

  

Icon and Image Sizes

enter image description here

enter image description here

我希望它对你有所帮助。

答案 1 :(得分:0)

我在上诉中错过了这一行。

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