How to reduce padding between UIBarButton items in UINavigationBar IOS 7?

3k views Asked by At
 UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [addButton setImage:[UIImage imageNamed:@"addButton.png"] forState:UIControlStateNormal];
    [addButton addTarget:self action:@selector(addSubProperty:) forControlEvents:UIControlEventTouchUpInside];
    [addButton setFrame:CGRectMake(0, 0,51,44)];

    UIBarButtonItem *firstBarButton = [[UIBarButtonItem alloc] initWithCustomView:addButton];

    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [deleteButton setImage:[UIImage imageNamed:@"deleteButton.png"] forState:UIControlStateNormal];
    [deleteButton addTarget:self action:@selector(deleteProperty:) forControlEvents:UIControlEventTouchUpInside];
    [deleteButton setFrame:CGRectMake(0, 0,50,44)];

    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    [negativeSpacer setWidth:-10];


    UIBarButtonItem *secondBarButton = [[UIBarButtonItem alloc]initWithCustomView:deleteButton];

    NSArray *navBtnArr = [[NSArray alloc] initWithObjects:negativeSpacer,firstBarButton,secondBarButton, nil];


    self.navigationItem.rightBarButtonItems = navBtnArr;

enter image description here

After this i got this result ,as you guys can see i did able to manage move my first barbutton left byt that negativeSpacer but i donot know how to reduce space between those two button.

and by doing this my back also goes disappear any idea will really appreciated .

1

There are 1 answers

0
jungledev On

Using Xcode 6.4, This worked beautifully for me with 1 line of code! https://stackoverflow.com/a/26469607/3634990

self.myBarButtonItem.imageInsets = UIEdgeInsetsMake(0, 25, 0, -25);

Note, this moves the image location, but not the touch area, so it's a great fix only if you want to move the image just a little bit.