I was using iOS 6.1 earlier, but now I have moved to iOS 7. Along with other problems, I have observed that in my navigation bar, the left space of left bar button item and right empty space of the right button bar item are quite more in IOS 7 than in iOS 6.
I need to know is there a way I can reduce empty spaces of left, right bar button items in navigation bar??
Thanks in advance.
This is my solution for
Swift 3.0
:Swift 3.1
To give left bar button item negative space:
for swift you can do this
Swift 3:
For Swift 2.0, this was my solution to get the following effect...
(the actual values may be different, depending on your situation)
Swift 2.2 UPDATE:
For Swift 2.2, the
action: Selector
method has changed, and should be typed as followscaptureButton.addTarget(self, action: #selector(YourViewController.showCaptureDetailsForm(_:)), forControlEvents: .TouchUpInside)
In order to fix this bug, you must subclass
UIButton
so that you can overridealignmentRectInsets
. From my testing, you'll need to return aUIEdgeInsets
with either a positive right offset or a positive left offset, depending on the button position. These numbers make no sense to me (at least one of them should be negative, according to common sense), but this is what actually works:Special thanks to @zev for suggesting I try adjusting
alignmentRectInsets
.