0

I have a custom back button created as UIBarButtonItem and inserted to navigationItem.leftBarButtonItem. I need to move it a little bit to the left. I was able to move with an image of UIBarButtonItem, but hit area of the button remained on original place.

Dimple
  • 788
  • 1
  • 11
  • 27
Lifeplus
  • 531
  • 2
  • 9
  • 22
  • 1
    Possible duplicate of [Change position of UIBarButtonItem in UINavigationBar](https://stackoverflow.com/questions/5761183/change-position-of-uibarbuttonitem-in-uinavigationbar) – Robert Dresler Nov 27 '18 at 13:11
  • I have answered this [here](https://stackoverflow.com/a/53028887/2395636). You can try! – Kamran Nov 27 '18 at 13:16
  • I was trying it, but I had still problem with hit (touch) zones. – Lifeplus Nov 27 '18 at 13:28

1 Answers1

0

Try to create a custom UIButton with the frame you want and after that create the UIBarButtonItem(customView: UIButton) like this for example

let button = UIButton(frame: CGRect(x: 0, y: 0, width: 45, height: 40))
let yourBarButton = UIBarButtonItem(customView: button)
  • This is how is the button created. Now I need to set X for some negative value to move it to the left, but it's not working. – Lifeplus Nov 27 '18 at 13:48
  • Try use this button.imageEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0); but remember that this function can change the image position of your button but not the area where it can be clicked – Francesco Destino Nov 27 '18 at 13:54