0

我正在使用带有以下代码的自定义标签栏:

UIImage *selectedImage0 = [UIImage imageNamed:@"HomeDB.png"];
UIImage *unselectedImage0 = [UIImage imageNamed:@"HomeLB.png"];    
UIImage *selectedImage1 = [UIImage imageNamed:@"ScheduleDB.png"];
UIImage *unselectedImage1 = [UIImage imageNamed:@"ScheduleLB.png"];

UIImage *selectedImage2 = [UIImage imageNamed:@"BuildingsDB.png"];
UIImage *unselectedImage2 = [UIImage imageNamed:@"BuildingsLB.png"];

UIImage *selectedImage3 = [UIImage imageNamed:@"InformationDB.png"];
UIImage *unselectedImage3 = [UIImage imageNamed:@"InformationLB.png"];

UIImage *selectedImage4 = [UIImage imageNamed:@"MoreDB.png"];
UIImage *unselectedImage4 = [UIImage imageNamed:@"MoreLB.png"];

UITabBar *tabBar = self.tabBarController.tabBar;

tabBar.tintColor = [UIColor redColor];
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
UITabBarItem *item3 = [tabBar.items objectAtIndex:3];
UITabBarItem *item4 = [tabBar.items objectAtIndex:4];

[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:unselectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:unselectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:unselectedImage2];
[item3 setFinishedSelectedImage:selectedImage3 withFinishedUnselectedImage:unselectedImage3];
[item4 setFinishedSelectedImage:selectedImage4 withFinishedUnselectedImage:unselectedImage4];

我的问题是自定义标签栏时,标签栏底部仍然有一个视图(我将颜色设置为红色)。看起来像这样:

http://farm3.staticflickr.com/2868/9668334491_eb3e39d001_b.jpg

有没有办法在不隐藏默认标签栏的情况下删除它并用自定义视图替换它?我已经在 Stackoverflow 的 UITabbar 参考中检查了它,但仍然找不到办法。

4

2 回答 2

0

你试试:

- (void)hideTabBar:(UITabBarController *) tabbarcontroller
{   
    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBarclass]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
        }
        else
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y + 36, view.frame.size.width, 480 - 36)];
        }
    }
}
于 2013-09-04T09:17:57.143 回答
0

我认为这就是你想要的,替换你的自定义 tabBar:

- (void)oppoHideTabBarViewController
    {
        if (self.tabBarViewController.tabBar.hidden == YES)
        {
            return;
        }

        UIView *contentView;

        if ( [[self.tabBarViewController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
        {
            contentView = [self.tabBarViewController.view.subviews objectAtIndex:1];
        }
        else
        {
            contentView = [self.tabBarViewController.view.subviews objectAtIndex:0];
        }

        contentView.frame = CGRectMake(contentView.bounds.origin.x,
                                       contentView.bounds.origin.y,
                                       contentView.bounds.size.width,
                                       contentView.bounds.size.height + self.tabBarViewController.tabBar.frame.size.height);

        self.tabBarViewController.tabBar.hidden = YES;

    }

    - (void)oppoShowTabBarViewController
    {
        if (self.tabBarViewController.tabBar.hidden == NO)
        {
            return;
        }

        UIView *contentView;

        if ([[self.tabBarViewController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]])
        {
            contentView = [self.tabBarViewController.view.subviews objectAtIndex:1];
        }
        else
        {
            contentView = [self.tabBarViewController.view.subviews objectAtIndex:0];
        }

        contentView.frame = CGRectMake(contentView.bounds.origin.x,
                                       contentView.bounds.origin.y,
                                       contentView.bounds.size.width,
                                       contentView.bounds.size.height - self.tabBarViewController.tabBar.frame.size.height);

        self.tabBarViewController.tabBar.hidden = NO;
    }
于 2013-09-04T08:14:40.960 回答