0

I'm currently creating a screen in which I use a UINavigationBar. When setting up the constraints, I have its leading margin = Superview's leading margin - 20, which renders in IB like so

constraints

When I add a UIBarButtonItem to the left (programmatically, or in IB), the button is rendered far too close to the left edge:

odd

Am I doing something wrong here?

Here are the constraints for this scene:

constraints

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Leon
  • 715
  • 1
  • 8
  • 22

2 Answers2

0

Instead of UIBarButtonItem drag UIButton via IB.

It will automatically create UI-components hierarchy like on picture bellow.

Then you'll be able to change content / title / image insets of button or alignment.

enter image description here

Yakiv Kovalskyi
  • 1,737
  • 1
  • 15
  • 29
0

I added a UIBarButtonItem.FixedSpace to my UINavigationItem as follows:

    let spacer = UIBarButtonItem(barButtonSystemItem: .FixedSpace, target: nil, action: nil)
    let editButton = UIBarButtonItem(barButtonSystemItem: .Edit, target: self, action: "toggleEditing")
    spacer.width = 6.0

    var leftItems = [UIBarButtonItem]()
    leftItems.append(spacer)
    leftItems.append(editButton)
    navigationItem.setLeftBarButtonItems(leftItems, animated: false)

Source: How to Edit Empty Spaces of Left, Right UIBarButtonItem in UINavigationBar [iOS 7]

Community
  • 1
  • 1
Leon
  • 715
  • 1
  • 8
  • 22