Search code examples
iosobjective-ciphoneuitabbaruitabbaritem

remove space below the UITabBarItem?


how do I reduce the distance between the two items?

my code:

-(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];
}

My 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";

}

I tried using the filtro.imageInsets = UIEdgeInsetsMake (6, 0, -6, 0); but it did not work


Solution

  • Try to add buttons this way:

        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];
    

    you need to mention the postions of x and y for the both UIViews as where ou want your buttons on the nav bar.