0
votes

I am setting a back button using navigtaionItem's leftItemsSupplementBackButton, and then setting a UIBarButtonItem as my leftBarButton. The problem is that the button is too far from the back button. How can I control its location and make it adjacent to the back button?

Below sample code sets the back button and the left bar button item.

UIBarButtonItem* bla = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"delete"] style:UIBarButtonItemStyleDone target:self action:nil];
self.navigationItem.leftItemsSupplementBackButton = YES;
self.navigationItem.leftBarButtonItem = bla;

Please find the attached screenshot.enter image description here

Thanks!

2

2 Answers

0
votes

Try this and change the value (CGFloat left) as you need.

   //UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
    self.navigationItem.leftBarButtonItem.imageInsets = UIEdgeInsetsMake(0, -25, 0, 0);
0
votes

You should add this statement following your code :

 [self.navigationItem.leftBarButtonItem setImageInsets:UIEdgeInsetsMake(0, -40, 0, 0)];//may be not -40 ,you can alter this argument.
                          //UIEdgeInsetsMake(topMargin, leftMargin,buttomMargin,rightMargin)

like this :

enter image description here

The best way to learn this method is using it !

So you should pass different argument to this method ' setImageInsets:(UIEdgeInset)' ,like this :

//UIEdgeInsetsMake(topMargin, leftMargin,buttomMargin,rightMargin)
[self.navigationItem.leftBarButtonItem setImageInsets:UIEdgeInsetsMake(-50, 0, 0, 0)];
[self.navigationItem.leftBarButtonItem setImageInsets:UIEdgeInsetsMake(0, -50, 0, 0)];
[self.navigationItem.leftBarButtonItem setImageInsets:UIEdgeInsetsMake(0, 0, 50, 0)];
[self.navigationItem.leftBarButtonItem setImageInsets:UIEdgeInsetsMake(0, 0, 0, 50)];

When you find you image's shape is changed, see the below:

If you find your image's shape of self.navigationItem.leftBarButtonItem is changed , you should code like this:

 [self.navigationItem.leftBarButtonItem setImageInsets:UIEdgeInsetsMake(0, -40, 0, 40)];

The reason is that: enter image description here

Hope it help you !