Ios 选项卡栏上的图像显示不正确。。在顶部显示一个额外的行-已更新

Ios 选项卡栏上的图像显示不正确。。在顶部显示一个额外的行-已更新,ios,iphone,uitabbarcontroller,Ios,Iphone,Uitabbarcontroller,我添加了一个ImageView作为选项卡栏的子视图,该选项卡栏有三个NavigationController。当我点击tabBarController的任何选项卡时,imageView上的图像会相应地改变,图像显示选定的特定选项卡和未选定的其他选项卡 但是,图像始终在选项卡栏上显示一条额外的线。看起来它已经越过了标签栏的限制。对于非视网膜iPhone,我的图像尺寸为320x64像素,对于视网膜iPhone,图像尺寸为640x128像素 下面是我如何为image视图和tabBarControlle

我添加了一个ImageView作为选项卡栏的子视图,该选项卡栏有三个NavigationController。当我点击tabBarController的任何选项卡时,imageView上的图像会相应地改变,图像显示选定的特定选项卡和未选定的其他选项卡

但是,图像始终在选项卡栏上显示一条额外的线。看起来它已经越过了标签栏的限制。对于非视网膜iPhone,我的图像尺寸为320x64像素,对于视网膜iPhone,图像尺寸为640x128像素

下面是我如何为image视图和tabBarController声明实例变量的

@interface HomePageViewController ()<UITabBarControllerDelegate>
{
    UIImageView* tabBarView;
    UITabBarController *tabBarController;
}




-(UITabBarController *) configureTheTabBarControllerWithNavControllerAtIndex:(NSInteger)index
{

    UINavigationController *customerCareNavController;
    UINavigationController *accAndContactsNavController;
    UINavigationController *purchaseOrderNavController;

    CustomerCareViewController *custCareVC;
    PurchaeOrderViewController *POController;
    AccountsAndContactsViewController *accAndContactsController;


        custCareVC = [[CustomerCareViewController alloc] initWithNibName:@"CustomerCareViewController_iPhone" bundle:NULL];
        POController = [[PurchaeOrderViewController alloc] initWithNibName:@"PurchaeOrderViewController_iPhone" bundle:NULL];
        accAndContactsController = [[AccountsAndContactsViewController alloc] initWithNibName:@"AccountsAndContactsViewController_iPhone" bundle:NULL];

    customerCareNavController = [[UINavigationController alloc] initWithRootViewController:custCareVC];

    purchaseOrderNavController = [[UINavigationController alloc] initWithRootViewController:POController];

    accAndContactsNavController = [[UINavigationController alloc] initWithRootViewController:accAndContactsController];

    tabBarController = [[UITabBarController alloc] init];

    tabBarController.viewControllers = [NSArray arrayWithObjects:customerCareNavController,accAndContactsNavController,purchaseOrderNavController, nil];

    switch (index) {
        case 0:
            tabBarController.selectedIndex = 0;
            break;

        case 1:
            tabBarController.selectedIndex = 1;
            break;

        case 2:
            tabBarController.selectedIndex = 2;
            break;
    }

    tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_mypeople.png"]];

    tabBarView.frame = CGRectMake(0, -15, 320, 64);

    [tabBarController.tabBar addSubview:tabBarView];

    tabBarController.delegate = self;

    [self selectTabBarIndex:index];

    [self presentViewController:tabBarController animated:YES completion:NULL];

    return tabBarController;
}

-(void)tabBarController:(UITabBarController *)TBController didSelectViewController:(UIViewController *)viewController
{
    NSUInteger indexSelected = [[TBController viewControllers] indexOfObject:viewController];
    [self selectTabBarIndex:indexSelected];
}

- (void) selectTabBarIndex:(NSInteger)index
{
    switch (index)
    {
        case 0:
            tabBarView.image=[UIImage imageNamed:@"tab_myCalendar.png"];
            break;
        case 1:
            tabBarView.image=[UIImage imageNamed:@"tab_myDetails.png"];
            break;
        case 2:
            tabBarView.image=[UIImage imageNamed:@"TabBarItem_PO.png"];
            break;
    }
}
请看截图

将barStyle设置为黑色会得到以下结果


该行有点褪色,但仍然可见。

下面的代码将从选项卡栏中删除该行

 if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0) {
    tabbarController.tabBar.barStyle=UIBarStyleBlackOpaque;
}

下面的代码将从选项卡栏中删除行

 if ([[[UIDevice currentDevice]systemVersion]floatValue]>=7.0) {
    tabbarController.tabBar.barStyle=UIBarStyleBlackOpaque;
}

嘿,我试过一些东西,效果不错

tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_mypeople.png"]];

    tabBarView.frame = CGRectMake(0, 0, 320, tabBarController.tabBar.frame.size.height);
但是,图像显示有点拉伸

写这篇文章是为了不拉伸:这将像一个符咒一样有效


嘿,我试过一些东西,效果不错

tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_mypeople.png"]];

    tabBarView.frame = CGRectMake(0, 0, 320, tabBarController.tabBar.frame.size.height);
但是,图像显示有点拉伸

写这篇文章是为了不拉伸:这将像一个符咒一样有效


在应用程序中编写此委托

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions


    UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

    [[UITabBar appearance] setBackgroundImage:tabBackground];

    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tab_select_indicator"]];

在应用程序中编写此委托

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions


    UIImage *tabBackground = [[UIImage imageNamed:@"tab_bg"]resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];

    [[UITabBar appearance] setBackgroundImage:tabBackground];

    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tab_select_indicator"]];

与其将图像作为子视图添加到图像视图中,不如将图像作为选项卡栏的背景图像添加,并将阴影图像设置为空图像,线条为阴影图像

tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tab_mypeople.png"];
tabBarController.tabBar.shadowImage = [UIImage new];
如果出于某种原因,您仍然需要使用子视图而不是背景图像,则可以继续执行问题中的操作,但将背景图像和阴影图像都设置为空图像如果不同时设置自定义背景图像,则无法设置自定义阴影图像。这将消除阴影图像线

tabBarController.tabBar.backgroundImage = [UIImage new];
tabBarController.tabBar.shadowImage = [UIImage new];
tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubview:tabBarView];

与其将图像作为子视图添加到图像视图中,不如将图像作为选项卡栏的背景图像添加,并将阴影图像设置为空图像,线条为阴影图像

tabBarController.tabBar.backgroundImage = [UIImage imageNamed:@"tab_mypeople.png"];
tabBarController.tabBar.shadowImage = [UIImage new];
如果出于某种原因,您仍然需要使用子视图而不是背景图像,则可以继续执行问题中的操作,但将背景图像和阴影图像都设置为空图像如果不同时设置自定义背景图像,则无法设置自定义阴影图像。这将消除阴影图像线

tabBarController.tabBar.backgroundImage = [UIImage new];
tabBarController.tabBar.shadowImage = [UIImage new];
tabBarView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"tab_mypeople.png"]];
tabBarView.frame = CGRectMake(0, -15, 320, 64);
[tabBarController.tabBar addSubview:tabBarView];

此不透明样式对我有效,请尝试设置其他样式,并希望它解决您的pblm:此不透明样式对我有效,请尝试设置其他样式,并希望它解决您的pblm:@Coder123,如果使用背景图像不适合您的情况,我愿意回答。@Coder123,如果使用背景图像对你的案例不起作用,我愿意接受我的答案。它有助于保持它,它有助于保持它