我正在尝试更改应用程序中Tab栏的图像。当我改变图像时,它给了我一个空白图像。
答案 0 :(得分:3)
不,您可以将.icon图像用于具有透明背景和黑白的tabbar。也可以设置tabbar的颜色。
tabbar Color
CGRect frame = CGRectMake(0.0, 0, 320, 48);
UIView *v = [[UIView alloc] initWithFrame:frame];
[v setBackgroundColor:[UIColor colorWithRed:0.2 green:0.8 blue:0.4 alpha:0.3]];
//[v setAlpha:1.0];
[[tabbar tabBar] insertSubview:v atIndex:0];
[v release];
答案 1 :(得分:3)
所有这些都是可能的!
UIImage *selectedImage0 = [UIImage imageNamed:@"TabBa1selected.png"];
UIImage *selectedImage1 = [UIImage imageNamed:@"TabBa2selected.png.png"];
UIImage *selectedImage2 = [UIImage imageNamed:@"TabBa3selected.png.png"];
UITabBar *tabBar = self.tabBarController.tabBar;
UITabBarItem *item0 = [tabBar.items objectAtIndex:0];
UITabBarItem *item1 = [tabBar.items objectAtIndex:1];
UITabBarItem *item2 = [tabBar.items objectAtIndex:2];
[item0 setFinishedSelectedImage:selectedImage0 withFinishedUnselectedImage:selectedImage0];
[item1 setFinishedSelectedImage:selectedImage1 withFinishedUnselectedImage:selectedImage1];
[item2 setFinishedSelectedImage:selectedImage2 withFinishedUnselectedImage:selectedImage2];
UIImage* tabBarBackground = [UIImage imageNamed:@"tabBarBackground.png"];
UIImage* tabBarSelected = [UIImage imageNamed:@"SelectedImage.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];
[[UITabBar appearance] setSelectionIndicatorImage:tabBarSelected];
答案 2 :(得分:1)
您通常会在AppDelegate类中为标签栏设置图像。它可能有一个标签栏控制器定义为_tabBarController,因此代码将是:
[[_tabBarController tabBar] setBackgroundImage:[UIImage imageNamed:@"imageName.png"]];
如果提供的图像尺寸合适或可伸缩,那么它将是该图像,否则它将是平铺图像,但填充标签栏需要多次。
如果您愿意,也可以更改标签颜色。