Deprecated iOS methods

I had a bit of a problem today designing a nice tabbed UI for iPhone.

I wanted to manipulate the existing image on the tab bar to change its colour and to prevent iOS from changing its shading when selected/deselected. I was using an old stack of code from the ‘appearance’ delegate of UITabBarItem.

The solution was to generate a local variable for the existing icon image and to set the rendering mode:

UIImage *inboxImage = [[UIImage imageNamed:@"inbox"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

Then simply use this image on the TabBar after getting hold of it via the root controller:

UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
UITabBarItem *tabInbox = [tabBar.items objectAtIndex:0];
[tabInbox setImage:inboxImage];

I hate coming across deprecated methods as the help documentation isn’t too hot. Stack Overflow is usually pretty good, though.

Leave a Reply

Your email address will not be published. Required fields are marked *