Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you're interested in an exact replica of the UITabBarItem filter, then try this solution. You don't need to include any extra images into your project. </p> <p>I'm fully aware that this is a total hack and I make no promises as to compatibility in the future, but it works in both iOS 5 and iOS 6 as far as I can tell, and with proper error handling I think it can be useful. Here it goes:</p> <pre><code>UIImage *grayTabBarItemFilter(UIImage *image) { UITabBar* bar = [[UITabBar alloc] init]; UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:@"" image:image tag:0]; [bar setItems:@[item]]; [[[[UIApplication sharedApplication] windows] lastObject] addSubview:bar]; UIImage* returnImage; for(UIView* view in bar.subviews) { for(UIView* small in view.subviews) { if([small respondsToSelector:@selector(image)]) { returnImage = [(UIImageView*)small image]; } } } [bar removeFromSuperview]; return returnImage ? returnImage : image; } UIImage *blueTabBarItemFilter(UIImage *image) { UITabBar* bar = [[UITabBar alloc] init]; UITabBarItem* item = [[UITabBarItem alloc] initWithTitle:@"" image:image tag:0]; [bar setItems:@[item]]; [bar setSelectedItem:item]; [[[[UIApplication sharedApplication] windows] lastObject] addSubview:bar]; UIImage* returnImage; for(UIView* view in bar.subviews) { NSInteger count = 0; for(UIView* small in view.subviews) { if([small respondsToSelector:@selector(image)]) { count++; if(count &gt; 1) { returnImage = [(UIImageView*)small image]; } } } } [bar removeFromSuperview]; return returnImage ? returnImage : image; } </code></pre> <p>Again, I'm aware that this is a shaky solution at best, but if you're interested in a perfect replica, here it is.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload