Iphone XCode:从特定选项卡中删除选择指示器图像

Iphone XCode:从特定选项卡中删除选择指示器图像,iphone,objective-c,xcode,uitabbarcontroller,Iphone,Objective C,Xcode,Uitabbarcontroller,我使用的是一个自定义选项卡栏图像,中间的选项卡也是一个自定义图像(很像旧版本的Instagram) 以下是我的一些代码: UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController; UITabBar *tabBar = tabBarController.tabBar; [tabBar setBackgroundImage:[UIImage imageNa

我使用的是一个自定义选项卡栏图像,中间的选项卡也是一个自定义图像(很像旧版本的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"]];
这很有效,但我有一个问题无法解决。默认情况下,所选选项卡具有浅灰色背景。这是一个效果,我想保留,但不为中间标签。中间的选项卡是一个较大的圆形图像,选中它时会发生变化,但仍会显示灰色背景


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

好的,因此在这些情况下,午餐时间散步确实很有帮助。这是我对其他有类似问题的人的回答

我首先将
包含在我的应用程序委托的.h中。在
didfishlaunchingwithoptions
方法中,我设置了选项卡栏的委托:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
tabBarController.delegate = self;
然后我可以使用此方法切换是否显示背景图像:

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

好的,所以在这种情况下,午餐时间散步真的很有帮助。这是我对其他有类似问题的人的回答

我首先将
包含在我的应用程序委托的.h中。在
didfishlaunchingwithoptions
方法中,我设置了选项卡栏的委托:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
tabBarController.delegate = self;
然后我可以使用此方法切换是否显示背景图像:

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

我已经尝试在代码中实现了这一点。但是,我在故事板中创建了原始的选项卡栏,当我在我的应用程序代理中添加选项卡栏时,它似乎没有被覆盖。我想知道我会怎么做

我可以像这样覆盖选项卡栏项

//create new tab bar appearance
UITabBar *tabBar = [UITabBar appearance];
//set background image
[tabBar setBackgroundImage:[UIImage imageNamed:@"menu.png"]];
//create a colour and apply it as tint colour when items aren't selected.
UIColor *color=[UIColor colorWithRed:64.0/255.0 green:147.0/255.0 blue:52.0/255.0 alpha:255.0];
UIColor *colorSelected=[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
[tabBar setTintColor:color];
[tabBar setSelectedImageTintColor:colorSelected];

[tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"selection-tab.png"]];

所有这些都只是在didfinishloadingwithoptions中,我已经尝试在代码中实现了这一点。但是,我在故事板中创建了原始的选项卡栏,当我在我的应用程序代理中添加选项卡栏时,它似乎没有被覆盖。我想知道我会怎么做

我可以像这样覆盖选项卡栏项

//create new tab bar appearance
UITabBar *tabBar = [UITabBar appearance];
//set background image
[tabBar setBackgroundImage:[UIImage imageNamed:@"menu.png"]];
//create a colour and apply it as tint colour when items aren't selected.
UIColor *color=[UIColor colorWithRed:64.0/255.0 green:147.0/255.0 blue:52.0/255.0 alpha:255.0];
UIColor *colorSelected=[UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0];
[tabBar setTintColor:color];
[tabBar setSelectedImageTintColor:colorSelected];

[tabBar setSelectionIndicatorImage:[UIImage imageNamed:@"selection-tab.png"]];
所有这些都只是在didfinishloadingwithoptions中