我知道可以使用在 iOS 5 中自定义 UITabBarItem
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_sel"]];
tabbar_sel 图像的宽度为 120px (640px/5)。对于横向模式,我需要将其更改为 190x 宽度的图像。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
NSLog(@"landscape.");
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_sel_l"]];
} else {
NSLog(@"normal.");
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_sel"]];
}
}
但是,这不起作用,无论是在委托类中还是在 ViewController 中。我也已经尝试过了,但这会导致崩溃。
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_sel"]
forBarMetrics:UIBarMetricsDefault];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_sel_l"] forBarMetrics:UIBarMetricsLandscapePhone];