objective-c - iOS 7 过度导航栏按钮填充

我在使用 LeftBarItems 和 RightBarItems 时遇到了过多的 UIBarButtonItem 填充/间距(见下图)。 UIBarButtonItems 上使用的图标不包含额外的填充。所以我想知道是什么原因造成的?

最佳答案

我使用它来删除第一项之前的空间。

但是,它在 UIBarButtonSystemItemAdd 等系统项之间不起作用,仅适用于具有图像的 UIBarButtonItem。

@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

像这样使用它:


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];

https://stackoverflow.com/questions/18897470/

相关文章:

ios - 选择时如何更改 UITableViewCell 的颜色?

ios - AVPlayer 和 Video 的屏幕截图

ios - 不支持推送导航 Controller

objective-c - 实现 -hash/-isEqual :/-isEqualTo. ..:用

ios - 使用 Xcode 进行模拟时,PerformFetchWithCompletionHan

objective-c - Xcode:可以为协议(protocol)接口(interface)所需

ios - 了解一对多的核心数据删除规则

ios - 我可以设置 `attributedText` 的 `UILabel` 属性吗

ios - 检测设备是否支持电话?

iphone - 所有文本字段的 resignFirstResponder