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.
Based on @C_X his answer I've created a category which adds and positions the UIBarButtonItem based on the iOS version of the current device.
In your view controller you can now use
[self.navigationItem addLeftBarButtonItem:leftBarButtonItem];
and[self.navigationItem addRightBarButtonItem:rightBarButtonItem];
I've also tried subclassing
UIButton
and override-alignmentRectInsets
but this gave me problems with transitions between views.Following smek's lead I made a category but modified it to provide backwards compatibility rather than forwards. I setup everything to work how I want it in iOS 7 and then if the user is running something lower I start mucking with things.
And then to get this globally, I have a thin
UIViewController
subclass that all of my view controllers inherit from.I realize that I am checking the OS version twice (once in
INFViewController
and again in the category), I left it in the category incase I want to use this as a one-off anywhere in the project.I believe you need to use a custom button with a
UIButton
subclass, and in your subclass, override-alignmentRectInsets
. I forget whether you need a positive or negative value for the appropriate edge to get it to shift correctly, but if one doesn’t work, try the other.I was also facing this problem. I also have feelings that in iOS 7 there is more space. And I figured out that this is about 10 points more. I usually use negative spaces when I want for
LeftBarItemButton
to start from the edge. This can be useful for you as well.Nice decision, thanks a lot! I needed to add just two elements to the left side of navigation header. This is my solution: