Question

I tried to figure out how to change the stroke of the selected Tabbar Icon. Its usally cyan like the tint of the selected icon. I already changed the tint and the indicator image of the selected icon like this: self.tabBarController.tabBar.selectedImageTintColor = [UIColor grayColor]; self.tabBarController.tabBar.selectionIndicatorImage = [UIImage imageNamed:@"selectedTab.png"];

But now i still got this cyan stroke around the icon

Image

Does anyone know the code for that because i couldn't find it

Was it helpful?

Solution

I've noticed this before as well. I ended up just setting the selected and unselected image manually instead of having it render the color for me.

You can then use Photoshop or your favourite image editing software to design two images for every tab. One image will be the tab icon when the tab is selected the other image would be for the tab when it is not selected. You will want to apply the tint colour yourself in Photoshop.

Once you have all your images imported into Xcode you can set them on the desired UITabBarItem. I usually set these within my View Controllers init function.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"my-selected-icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"my-deselected-icon"]];
    }
    return self;
}

You will have to do this for every View Controller that is on your Tab Bar.

OTHER TIPS

Try this code, place it in viewDidLoad:

for (UITabBarItem * barItem in theTabBar.items) {
    UIImage * image = barItem.image;
    [barItem setFinishedSelectedImage:image withFinishedUnselectedImage:image];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top