How to Edit Empty Spaces of Left, Right UIBarButtonItem in UINavigationBar iOS 7
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
On iOS 7, navigation bar button spacing often feels wider than a custom design expects. The usual fix is to stop relying on the default placement and instead add a spacer item or a custom view so you can control how close the visible button sits to the edge.
Why the Default Spacing Exists
UINavigationBar applies built-in margins so controls are not flush against the screen edge. That default works well for standard system buttons, but image buttons and tightly aligned custom layouts often look slightly off.
In iOS 7, developers commonly corrected this with a fixed-space UIBarButtonItem inserted before the real button item. The spacer width can even be negative, which shifts the visible item outward.
Use a Fixed-Space Bar Button Item
If you already have a normal UIBarButtonItem, a spacer is the simplest adjustment.
The same pattern works on the right side:
There is no universal width that fits every asset. Values like -5, -10, or -16 are just starting points. You should tune visually against your icon size and the rest of the navigation bar.
Use a Custom View for Finer Layout Control
If spacing is only one part of the problem, create a custom UIButton and wrap it in a UIBarButtonItem. That gives you control over frame size, edge insets, and touch handling.
This approach is better when the icon needs to move without shrinking the tappable area. It also helps when you want a nonstandard image size or a text-and-icon combination.
Decide Between Spacer and Custom View
Use a spacer when you like the default button behavior and only need the item to sit a few points closer to the edge. Use a custom view when you need to tune multiple properties at once, such as icon position, width, font, or touch region.
For older codebases, keep the workaround local if possible. A global appearance hack can seem convenient at first, but it usually spreads layout assumptions into screens that never needed the adjustment.
Common Pitfalls
The first mistake is pushing the item too close to the edge. A design may look cleaner, but the button still needs a comfortable tap target. Test the interaction on a real device, not only in the simulator.
Another issue is assuming an iOS 7 spacing trick behaves the same on later releases. Navigation bar layout changed over time, so negative spacers that looked correct on iOS 7 can create odd alignment elsewhere.
Custom views can also break expected behavior if the frame is too small or hit testing is misaligned. When you wrap a UIButton, make sure its bounds are explicit and its action still fires reliably.
Finally, change both sides with care. Pulling the left item outward while leaving the right item unchanged can make the whole bar feel unbalanced even if the individual adjustment is technically correct.
Summary
- On iOS 7, extra bar button padding is commonly adjusted with a fixed-space
UIBarButtonItem. - A negative spacer width moves the visible button closer to the screen edge.
- A custom
UIButtoninside a bar button item gives finer control than the default item. - Keep the touch area usable even when tightening visual spacing.
- Revalidate the layout before reusing the same workaround on newer iOS versions.

