iOS7 过多的导航栏按钮填充 [英] iOS7 excessive navigationbar button padding
本文介绍了iOS7 过多的导航栏按钮填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用 LeftBarItems 和 RightBarItems 时遇到过多的 UIBarButtonItem 填充/间距(见下图).UIBarButtonItems 上使用的图标不包含额外的填充.所以我想知道这是什么原因造成的?
I'm experiencing excessive UIBarButtonItem padding/spacing when using the LeftBarItems and RightBarItems (see image below). The icons used on the UIBarButtonItems do not contain extra padding. So I would like to know what's causing this?
推荐答案
我使用它是为了删除第一项之前的空间.
I use this in order to remove space before the first item.
但是,它在 UIBarButtonSystemItemAdd
等系统项之间不起作用,仅适用于具有图像的 UIBarButtonItem.
However it doesn't work between system items like UIBarButtonSystemItemAdd
, only with UIBarButtonItem that has an image.
@interface UIBarButtonItem (NegativeSpacer)
+(UIBarButtonItem*)negativeSpacerWithWidth:(NSInteger)width;
@end
@implementation UIBarButtonItem (NegativeSpacer)
+(UIBarButtonItem*)negativeSpacerWithWidth:(NSInteger)width {
UIBarButtonItem *item = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil
action:nil];
item.width = (width >= 0 ? -width : width);
return item;
}
@end
<小时>
像这样使用它:
Use it like this:
UIBarButtonItem *item0 = [UIBarButtonItem negativeSpacerWithWidth:13];
UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"sidebar.png"]
style:UIBarButtonItemStylePlain
target:vc
action:@selector(sideMenuAction:)];
NSArray* items = @[item0, item1];
[vc.navigationItem setLeftBarButtonItems:items animated:NO];
[vc.navigationItem setLeftItemsSupplementBackButton:YES];
这篇关于iOS7 过多的导航栏按钮填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文