Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setSelectionIndicatorImage is of wrong size for iphone 6 and iPhone 6+

I am using following method to set selection indicator for selected tab bar item. It works well for iPhone 4/4s/5/5s but not in iphone 6/6+.

[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"activeshape.png"] ];

Any suggestion

like image 977
Saqib Omer Avatar asked Oct 21 '14 10:10

Saqib Omer


1 Answers

EDIT: IT seems that after all this solution should work, I had some issues with cache

UIImage *selTab = [[UIImage imageNamed:@"tabHighlight"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
CGSize tabSize = CGSizeMake(CGRectGetWidth(self.view.frame)/5, 49);
UIGraphicsBeginImageContext(tabSize);
[selTab drawInRect:CGRectMake(0, 0, tabSize.width, tabSize.height)];
UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//
[self.tabBar setSelectionIndicatorImage:reSizeImage];

tabHiglight is a png of 82x49, I've tested with other sizes but this seems to fit best. I divide the width of the frame by the number of items I have in the tabBar - in my case 5, then I create a new UIImage of the "right" size and set it as the selectionIndicatorImage.

like image 121
tagyro Avatar answered Sep 25 '22 01:09

tagyro