Ios setSelectionIndicatorImage对于iphone 6和iphone 6+;
我使用以下方法为所选选项卡栏项目设置选择指示器。它适用于iPhone4/4s/5/5s,但不适用于iPhone6/6+Ios setSelectionIndicatorImage对于iphone 6和iphone 6+;,ios,objective-c,Ios,Objective C,我使用以下方法为所选选项卡栏项目设置选择指示器。它适用于iPhone4/4s/5/5s,但不适用于iPhone6/6+ [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"activeshape.png"] ]; 任何建议编辑:似乎在所有这些解决方案都能正常工作之后,我的缓存出现了一些问题 UIImage *selTab = [[UIImage imageNamed:@"tabHighlight"] i
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"activeshape.png"] ];
任何建议编辑:似乎在所有这些解决方案都能正常工作之后,我的缓存出现了一些问题
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,我已经用其他尺寸进行了测试,但这似乎最适合。
我将框架的
宽度
除以选项卡栏中的项目数-在我的示例5中,然后创建一个“正确”大小的新UIImage,并将其设置为选择指示图像
这是我的自动调整UIAbbarController
子类。只要提供一个图像,它就会适应所有已知的iPhone和iPad。它还将在trait集合发生变化时更新大小,以支持所有新的iPad功能和轮换
import UIKit
class TabBarController: UITabBarController {
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
updateSelectionIndicatorImage()
}
override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) {
super.traitCollectionDidChange(previousTraitCollection)
updateSelectionIndicatorImage()
}
func updateSelectionIndicatorImage() {
let width = CGRectGetWidth(tabBar.bounds) > 420 ? 420 : CGRectGetWidth(tabBar.bounds)
var selectionImage = UIImage(named: "TabSelectionIndicator")
let tabSize = CGSizeMake(width/5, 49)
UIGraphicsBeginImageContext(tabSize)
selectionImage?.drawInRect(CGRectMake(0, 0, tabSize.width, tabSize.height))
selectionImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
tabBar.selectionIndicatorImage = selectionImage
}
}
为了支持2倍和3倍的设备,我使用了:UIGraphicsBeginImageContextWithOptions(tabSize,NO,[UIScreen mainScreen].scale);