【发布时间】:2013-07-05 11:49:06
【问题描述】:
默认情况下,在 UITabbar 中,选定的 UITabBarItem 上有一个光泽突出显示。
是否可以去除光泽高光遮罩?
谢谢。
【问题讨论】:
默认情况下,在 UITabbar 中,选定的 UITabBarItem 上有一个光泽突出显示。
是否可以去除光泽高光遮罩?
谢谢。
【问题讨论】:
[[UITabBar appearance] setSelectionIndicatorImage:[[UIImage alloc] init]];
像魅力一样工作!
【讨论】:
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage {anImage}]]
这会影响您使用的每个标签栏(甚至是子类)
如果您在此处使用与标签栏背景颜色相同的图像,您将不会看到指示符。
也许您甚至可以使用全透明图像,或 1px*1px 的图像。
【讨论】:
如果您使用自定义图像自定义标签栏项目,您可以这样做。 我通过将背景图像添加到标签栏来自定义标签栏项目,其中所有标签都已绘制,一个标签处于选中状态,其他标签处于未选中状态。在每个 didSelectViewController 中,我都会更改背景图像。 然后,我将背景图像视图放在前面,并添加带有所需标题的自定义标签。
结果:我自定义了没有光泽效果的标签栏。有趣的是,UITabBarButtons 在背景图片下,但仍然可以选择。
代码是这样的:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
[self customizeTabBar];
}
- (void)customizeTabBar {
NSString *imageName = [NSString stringWithFormat:@"tabbg%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.
}
也许你会对这个感兴趣:)
【讨论】:
根据 Apple 的文档,您可以实施:
(void)setFinishedSelectedImage:
(UIImage *)selectedImage withFinishedUnselectedImage:
(UIImage *)unselectedImage
这是一个UITabBar方法
【讨论】: