如何删除UITabBar中的行?

时间:2014-06-24 22:21:41

标签: ios objective-c uitabbar

帮助删除标签栏中的行!

image

`[[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];`  - NOT WORK

CODE:

[[UITabBar appearance] setBarTintColor:[UIColor colorWithRed:54.0f/255.0f green:62.0f/255.0f blue:69.0f/255.0f alpha:1.0f]];
    [[UITabBar appearance] setTintColor:[UIColor whiteColor]];
    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc] init]];


    [[self.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:@"barMap.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"barMapNo.png"]];

    [[self.tabBar.items objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:@"barNews.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"barNewsNo.png"]];

    [[self.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:@"barNew.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"barNewNo.png"]];

3 个答案:

答案 0 :(得分:0)

当图像大于按钮框架时,您看起来喜欢将图像设置为标签栏项目(使用默认框架)。你需要更换整个按钮!

UIImage *image = [UIImage imageNamed:@"image"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, image.size.width, image.size.height);
[button setImage:image forState:UIControlStateNormal];
UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
[tabBar setItems:@[ barButton, /* etc */ ]];

答案 1 :(得分:0)

如果您要删除shadowImage,那么只需执行您正在执行的操作,但将其分配给shadowImage而不是backgroundImage

答案 2 :(得分:0)

试试这个,

//Remove shadow image by assigning nil value.
[[UITabBar appearance] setShadowImage: nil];

// or 

// Assing UIImage instance without image reference
[[UITabBar appearance] setShadowImage: [[UIImage alloc] init]];

这是阴影图像的苹果指南。

  

默认为零。当非零时,显示自定义阴影图像而不是   默认阴影图像。要显示自定义阴影,请自定义   必须使用-setBackgroundImage设置背景图像:(如果是   使用默认背景图像,默认阴影图像将是   使用)。