【问题标题】:when i am adding in UITabBar background image then height increase automatically当我添加 UITabBar 背景图像时,高度会自动增加
【发布时间】:2016-05-02 19:14:49
【问题描述】:

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

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

}

【问题讨论】:

  • 你想在哪里设置背景图片以查看控制器背景或 UITabbar 的背景?
  • 我正在添加 appdelegate 你可以检查我的代码谢谢
  • 当我评论这条线工作正常时 // [[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"tabbarimage.png"]];
  • 最近控制器数字键盘和联系人的唯一问题没有问题

标签: ios objective-c ios7


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    首先检查您的图像大小。

    来自苹果文档 TabBar 上图片的最大尺寸 为 30x30(视网膜显示屏为 60x60)。

    我认为如果不拉伸 UIimageview 之类的图像,就不可能占据 TabBar 的整个高度。所以,在我看来,最好的解决方案是使用 imageInset 在 TabBar 中将图像居中。

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

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

    欲了解更多详情,请查看以下链接的 Apple 文档。

    Icon and Image Sizes

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 2018-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多