XCode:从特定选项卡中删除选择指示器图像 [英] XCode: Remove Selection Indicator Image from a particular tab

查看:206
本文介绍了XCode:从特定选项卡中删除选择指示器图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自定义标签栏图像,中间标签也是自定义图像(很像旧版本的Instagram)。

I am using a custom tab bar image and the middle tab is also a custom image (much like an older version of Instagram).

这是我的一些代码:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    UITabBar *tabBar = tabBarController.tabBar;

    [tabBar setBackgroundImage:[UIImage imageNamed:@"CustomTabBar.png"]];

    UITabBarItem *tabBarItem3 = [tabBar.items objectAtIndex:2];
    tabBarItem3.title = nil;
    tabBarItem3.image = nil;
    [tabBarItem3 setFinishedSelectedImage:[UIImage imageNamed:@"tab-button-selected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab-button.png"]];

这很好用,但我有一个问题我无法解决。默认情况下,所选选项卡具有浅灰色背景。这是我想保留的效果,但不适用于中间标签。中间选项卡是一个较大的圆形图像,在选中时会发生变化,但仍然会出现灰色背景。

This works great, but I have one issue I cannot fix. The selected tab has, by default, a light grey background. This is an effect which I would like to keep, but not for the middle tab. The middle tab is a larger round image which does change when it is selected, but still the grey background appears.

有没有办法删除它像 [tabBar setSelectionIndicatorImage:[[UIImage alloc] init]]; 但仅适用于该选项卡。或者,在app委托中,检测选项卡中的更改并将其删除?

Is there a way to remove this like [tabBar setSelectionIndicatorImage:[[UIImage alloc] init]]; but for that tab only. Or, in the app delegate, detect a change in tab and remove it there?

推荐答案

好的,所以结果很好午餐时间散步真的有助于这些情况。以下是我遇到类似问题的其他人的答案。

Ok, so it turns out a nice lunch time walk really helps in these situations. Here is my answer for anyone else who has a similar problem.

我首先在< UITabBarControllerDelegate> 中包含我的应用代表的.h。在 didFinishLaunchingWithOptions 方法中,我设置标签栏的委托:

I first include <UITabBarControllerDelegate> in the .h of my app delegate. And in the didFinishLaunchingWithOptions method I set the delegate of the tab bar:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
tabBarController.delegate = self;

然后我可以使用此方法切换是否显示背景图片:

Then I can use this method to toggle whether or not to show the background image or not:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    UITabBar *tabBar = tabBarController.tabBar;
    if (tabBar.selectedItem == [tabBar.items objectAtIndex:2]) {
        [tabBar setSelectionIndicatorImage:[[UIImage alloc] init]];
    }
    else {
        [tabBar setSelectionIndicatorImage:nil];
    }
}

这篇关于XCode:从特定选项卡中删除选择指示器图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆