0

I am trying to create custom back bar button item using image. I've done it this way:

let image = UIImage(named: "Back")
self.navigationBar.backIndicatorImage = image
self.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "Back")
self.navigationBar.tintColor = UIColor.blackColor()

But here's result:enter image description here

As you can see, it should be moved a little down and a little right. I tried to add offset to image this way:

self.navigationBar.backIndicatorImage = image?.imageWithAlignmentRectInsets(UIEdgeInsetsMake(10, 40, 0, 0))

But it does not work, the same. Any ideas?

Nikita Zernov
  • 5,465
  • 6
  • 39
  • 70

1 Answers1

0

Although, I feel, there is a scope to move title bit up to match with back button, you can move nav bar button down by:

UINavigationBar.appearance().setTitleVerticalPositionAdjustment(5.0, forBarMetrics: UIBarMetrics.Default)

To move it to right, try adding a flexible space, something like:

let space = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
Abhinav
  • 37,684
  • 43
  • 191
  • 309
  • To move it down, I've put it in viewWillAppear method, but it does not work – Nikita Zernov Nov 04 '15 at 08:51
  • Can you try moving your bar button using `navBar.leftBarButtonItem?.backgroundVerticalPositionAdjustmentForBarMetrics(UIBarMetrics.Default)`. – Abhinav Nov 04 '15 at 09:02
  • Adding a custom button may instead give you more control on positioning. Take a look at this ObjC [SO Thread](http://stackoverflow.com/questions/18897470/ios7-excessive-navigationbar-button-padding) to get an idea. – Abhinav Nov 04 '15 at 09:13