在我的应用程序中,我有一个 UITabBar。我想隐藏/删除该选项卡栏项目选择样式,即光泽效果。是否可以通过编程方式进行操作?还有任何方法可以通过编程方式定位选项卡栏项目。
问问题
516 次
1 回答
0
试试这个代码可能对你有帮助......
// iOS 5.0+
[self.tabBar setSelectionIndicatorImage:[[[UIImage alloc] init]autorelease]];
// for earlier versions
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
[self customizeTabBar];
}
- (void)customizeTabBar {
NSString *imageName = [NSString stringWithFormat:@"tabBackground%i.png", tabBarCtrl.selectedIndex + 1];
for(UIView *view in tabBarCtrl.tabBar.subviews) {
if([view isKindOfClass:[UIImageView class]]) {
[view removeFromSuperview];
}
}
UIImageView *background = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]] autorelease];
[tabBarCtrl.tabBar insertSubview:background atIndex:0];
[tabBarCtrl.tabBar bringSubviewToFront:background];
//if needed, here must be adding UILabels with titles, I didn't need it.
}
于 2012-11-05T10:33:40.083 回答