1

i'm attempting to add a done button to my nav bar (built directly UINavigationBar not with a controller). The done button appears fine, the action works, but it has no padding from the edge of the nav bar.

i tried adding a second bar button item with fixed space but it has no effect.

what's even weirder to me is that when i tried adding the button twice [rightButton,rightButton]

it made space for 2 buttons but only the first one showed up the second one didn't actually appear.

thanks for you help i've attached some code and photos for reference.

enter image description here enter image description here

let rightButton = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Done, target: self, action: "doneAction:")

let rightButtonPadding = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FixedSpace, target: nil, action: nil)
            rightButtonPadding.width = 50

            let items = UINavigationItem()
            items.title = name.uppercaseString
            items.rightBarButtonItems = [rightButton,rightButtonPadding]
            items.hidesBackButton = true

            navBar.pushNavigationItem(items, animated: false)
stanley
  • 1,113
  • 1
  • 12
  • 26

2 Answers2

1

change the order to [rightButtonPadding ,rightButton]

From Documentation:

"Items are displayed right-to-left in the same order as they appear in the array. Thus, the first item in the array is the rightmost item and other items are added to the left of the previous item."

Teja Nandamuri
  • 11,045
  • 6
  • 57
  • 109
0

Try to play with UIBarButtonItemStyleDone/UIBarButtonItemStylePlain. Also please check this thread: iOS7 excessive navigationbar button padding

Community
  • 1
  • 1
timurbeg
  • 76
  • 6