iOS7 UI兼容 导航栏按钮边框 UINavigationItem left and right padding
iOS7之前的UI为:
而在iOS7中,由于设计方面的原因,使得UI变为:
修改的方法重写UINavigationItem的setLeftBarButtonItem和setRightBarButtonItem方法,使之与之前版本兼容;
代码如下:
@inte易做图ce UINavigationItem (margin)
@end
@implementation UINavigationItem (margin)
#if __IPHONE_OS_VERSION_MAX_ALLOWED > __IPHONE_6_1
- (void)setLeftBarButtonItem:(UIBarButtonItem *)_leftBarButtonItem
{
UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
spaceButtonItem.width = -12;
if (_leftBarButtonItem)
{
[self setLeftBarButtonItems:@[spaceButtonItem, _leftBarButtonItem]];
}
else
{
[self setLeftBarButtonItems:@[spaceButtonItem]];
}
[spaceButtonItem release];
}
- (void)setRightBarButtonItem:(UIBarButtonItem *)_rightBarButtonItem
{
UIBarButtonItem *spaceButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
spaceButtonItem.width = -12;
if (_rightBarButtonItem)
{
[self setRightBarButtonItems:@[spaceButtonItem, _rightBarButtonItem]];
}
else
{
[self setRightBarButtonItems:@[spaceButtonItem]];
}
[spaceButtonItem release];
}
#endif
@end
项目源码不做任何修改,问题解决;
添加Button:
UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:btnBack];
self.navigationItem.leftBarButtonItem = leftBarItem;
[leftBarItem release];
补充:移动开发 , IOS ,