【问题标题】:IOS remove space between each tab bar itemIOS删除每个标签栏项目之间的空间
【发布时间】:2016-11-09 06:19:59
【问题描述】:

这是我的标签栏:

我想制作如下设计的标签栏:

标签栏项目的标题为零(图片中的文字)。我在标签栏类中的代码如下:

- (void)viewDidLoad 
{
    [super viewDidLoad];
    self.tabBar.barTintColor = [UIColor colorWithRed:67/255.0 green:67/255.0 blue:67/255.0 alpha:1];
    for (UITabBarItem *tbi in self.tabBar.items) 
    {
        tbi.title = nil;
        tbi.image = [tbi.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        tbi.selectedImage = [tbi.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        tbi.imageInsets = UIEdgeInsetsMake(6.0, 0.0, -6.0, 0.0);
    }
}

我为标签栏项目尝试了多种尺寸,但它没有改变。请帮我解决这个问题 非常感谢!

【问题讨论】:

  • 我想你想试试自定义标签栏的使用。

标签: ios objective-c uitabbarcontroller


【解决方案1】:

你的代码是对的

您可以获取标签栏的特定项目并尝试设置不同的插图

 // UIEdgeInsets insets = {top, left, bottom, right};  

 UITabBarItem *tabBarItem1 = [self.tabBar.items objectAtIndex:0];
    UITabBarItem *tabBarItem2 = [self.tabBar.items objectAtIndex:1];
     UITabBarItem *tabBarItem3 = [self.tabBar.items objectAtIndex:2];
         UITabBarItem *tabBarItem4 = [self.tabBar.items objectAtIndex:3];
    tabBarItem1.imageInsets = UIEdgeInsetsMake(-6.0, -6.0, -6.0, -6.0);
    tabBarItem2.imageInsets = UIEdgeInsetsMake(-6.0, -6.0, -6.0, -6.0);
    tabBarItem3.imageInsets = UIEdgeInsetsMake(-6.0, -6.0, -6.0, -6.0);
   tabBarItem4.imageInsets = UIEdgeInsetsMake(-6.0, -6.0, -6.0, -6.0);

【讨论】:

    【解决方案2】:

    我认为您的解决方案是正确的。 imageInsets 改变 tabbaritem.image 的大小和位置。它在我的项目中运行良好。

    也许tbi.imageInsets = UIEdgeInsetsMake(-6.0, -6.0, -6.0, -6.0);更适合你的情况。

    如果你的文字和图片太接近,你应该调整图片本身,因为你的文字和你的图片是一致的

    【讨论】: