如何在选定的 UITabBar 项目上叠加?
Posted
技术标签:
【中文标题】如何在选定的 UITabBar 项目上叠加?【英文标题】:how to have a overlay on top of a select UITabBar item? 【发布时间】:2011-11-06 15:15:36 【问题描述】:有人知道如何在所选项目的顶部添加额外的叠加层吗?
后台在应用委托中完成。
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navbar_bgrd.png"]];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9)
//ios 5
[self.tabBarController.tabBar insertSubview:imageView atIndex:1];
else
//iOS 4.whatever and below
[self.tabBarController.tabBar insertSubview:imageView atIndex:0];
选中
未选中
【问题讨论】:
【参考方案1】:IOS 5 修复,UIappearance 功能
//set the background of tab bar
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navbar_bgrd.png"]];
if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9)
//iOS 5
//[self.tabBarController.tabBar insertSubview:imageView atIndex:1];
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_bgrd.png"]];
[[UITabBar appearance] setSelectionIndicatorImage:
[UIImage imageNamed:@"navbaractive.png"]];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor colorWithRed:75.0/255.0 green:75.0/255.0 blue:75.0/255.0 alpha:1.0], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIColor clearColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset,
nil] forState:UIControlStateSelected];
【讨论】:
以上是关于如何在选定的 UITabBar 项目上叠加?的主要内容,如果未能解决你的问题,请参考以下文章
如何摆脱UITabBar中第一个和最后一个项目之前和之后的空间?