0
我知道这是可能使用定制UITabBarItem
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_sel"]];
的tabbar_sel图像具有宽度120像素(640像素/ 5)来定制UITabBarItem在IOS 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];
感谢您的回答,但这不起作用。 – 2012-07-31 13:33:39
我检查了它并编辑了我的代码,这应该能够指示从纵向到横向的变化,反之亦然。 Hower我并没有声称与您提供的代码相结合,它会提供所需的效果。我不确定通过使用setSelectionIndicatorImage:它会自动重新绘制。 – 2012-07-31 13:41:28