删除 UITabBarItem 下面的 space?

remove space below the UITabBarItem?

如何缩小两个项目之间的距离?

我的代码:

-(void)setupRightMenuButton{
    filtro = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon-filtro-bar"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonFilter)];
    busca = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon-busca"] style:UIBarButtonItemStylePlain target:self action:@selector(moveToSearchView)];

    filtro.tintColor = [UIColor whiteColor];
    busca.tintColor = [UIColor whiteColor];

    filtro.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);
    busca.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

    [self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:busca, filtro, nil] animated:YES];
}

我的 viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupLeftMenuButton];

    [self.navigationController.navigationBar setBarTintColor: [UIColor colorWithRed:0.49 green:0.075 blue:0.082 alpha:1]]; /*#7d1315*/
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor]}];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

    [[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
                                                         forBarMetrics:UIBarMetricsDefault];
    [self setupRightMenuButton];
    self.title = @"Músicas";

}

我尝试使用 filtro.imageInsets = UIEdgeInsetsMake (6, 0, -6, 0); 但它不起作用

试试这样添加按钮:

    UIButton *but1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    UIView *but1View = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    [but1View addSubview:but1];
    UIBarButtonItem *rightButton1 = [[UIBarButtonItem alloc] initWithCustomView:but1View];

    UIButton *but2 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    UIView *but2View = [[UIView alloc] initWithFrame:CGRectMake(x, y, width, height)];
    [but2View addSubview:but2];
    UIBarButtonItem *rightButton2 = [[UIBarButtonItem alloc] initWithCustomView:but2View];

       self.navigationItem.rightBarButtonItems=@[ rightButton,rightButton2];

您需要提及两个视图的 x 和 y 的位置,作为您希望按钮在导航栏上的位置。

这段代码对我有用。尝试创建一个按钮,然后为其设置图像并设置按钮框架。

let button: UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
let image = UIImage(named: "your_image")!
button.setImage(image , forState: UIControlState.Normal)
// optional -------------
button.addTarget(self, action: "your_function", forControlEvents: UIControlEvents.TouchUpInside)
// ------------
button.frame = CGRectMake(0, 0, image.width, image.height)
let barButton = UIBarButtonItem(customView: button)

根据需要创建任意数量的 barButton,然后将它们添加到 navigationItem:

self.navigationItem.setRightBarButtonItems([barBtn1, barBtn2], animated: false)