How to Edit Empty Spaces of Left, Right UIBarButtonItem in UINavigationBar in iOS 7
最早的答案应该是在这里找到的:
link:http://stackoverflow.com/questions/18914812/how-to-edit-empty-spaces-of-left-right-uibarbuttonitem-in-uinavigationbar-in-io
然后,然后
在code4app上也有一些最先找到这个答案的人截了一段-> 如下答案~!
link:
做法是一样的。
原理看完之后都会觉得很简单,但是佩服第一个解决这个问题的人!
尽情效仿!
- (
void
)addLeftBarButtonItem:(
UIBarButtonItem
*)leftBarButtonItem
{
UIBarButtonItem
*negativeSpacer = [[
UIBarButtonItem
alloc
]
initWithBarButtonSystemItem
:
UIBarButtonSystemItemFixedSpace
target
:nil
action
:nil
];
if
([[[
UIDevice
currentDevice
]
systemVersion
]
floatValue
] >=
7
.0
) {
negativeSpacer
.width
= -
1
0
;
}
else
{
negativeSpacer
.width
=
0
;
[
self
setLeftBarButtonItem
:leftBarButtonItem];
}
[
self
setLeftBarButtonItems
:[
NSArray
arrayWithObjects
:negativeSpacer, leftBarButtonItem,
nil
]];
}
- (
void
)addRightBarButtonItem:(
UIBarButtonItem
*)rightBarButtonItem
{
UIBarButtonItem
*negativeSpacer = [[
UIBarButtonItem
alloc
]
initWithBarButtonSystemItem
:UIBarButtonSystemItemFixedSpace
target
:nil
action
:nil
];
if
([[[
UIDevice
currentDevice
]
systemVersion
]
floatValue
] >=
7
.0
) {
negativeSpacer
.width
= -
1
0
;
}
else
{
negativeSpacer
.width
=
0
;
}
[
self
setRightBarButtonItems
:[
NSArray
arrayWithObjects
:negativeSpacer, rightBarButtonItem,
nil
]];
}