对于iphone 6和iPhone 6+,setSelectionIndicatorImage的大小不正确 [英] setSelectionIndicatorImage is of wrong size for iphone 6 and iPhone 6+
问题描述
我正在使用以下方法为所选标签栏项目设置选择指示器。它适用于iPhone 4 / 4s / 5 / 5s但不适用于iphone 6/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"] ];
任何建议
推荐答案
编辑:似乎在所有这个解决方案应该工作之后,我遇到了一些缓存问题
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
是一个82x49的png,我已经测试过其他尺寸,但这似乎最合适。
我将框架的宽度
除以tabBar中的项目数 - 在我的情况下为5,然后我创建了一个新的UIImage 大小并将其设置为 selectionIndicatorImage
。
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
.
这篇关于对于iphone 6和iPhone 6+,setSelectionIndicatorImage的大小不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!