ios7 - 如何减少 UINavigationBar IOS 7 中 UIBarButton 项目之间的填充?

标签 ios7 uinavigationbar uibarbuttonitem uinavigationitem uiappearance

 UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [addButton setImage:[UIImage imageNamed:@"addButton.png"] forState:UIControlStateNormal];
    [addButton addTarget:self action:@selector(addSubProperty:) forControlEvents:UIControlEventTouchUpInside];
    [addButton setFrame:CGRectMake(0, 0,51,44)];

    UIBarButtonItem *firstBarButton = [[UIBarButtonItem alloc] initWithCustomView:addButton];

    UIButton *deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [deleteButton setImage:[UIImage imageNamed:@"deleteButton.png"] forState:UIControlStateNormal];
    [deleteButton addTarget:self action:@selector(deleteProperty:) forControlEvents:UIControlEventTouchUpInside];
    [deleteButton setFrame:CGRectMake(0, 0,50,44)];

    UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
    [negativeSpacer setWidth:-10];


    UIBarButtonItem *secondBarButton = [[UIBarButtonItem alloc]initWithCustomView:deleteButton];

    NSArray *navBtnArr = [[NSArray alloc] initWithObjects:negativeSpacer,firstBarButton,secondBarButton, nil];


    self.navigationItem.rightBarButtonItems = navBtnArr;

enter image description here

在此之后,我得到了这个结果,正如你们所看到的,我确实能够将我的第一个栏按钮向负间隔器左侧移动,但我不知道如何减少这两个按钮之间的空间。

通过这样做,我的背部也会消失,任何想法都会非常感激。

最佳答案

使用 Xcode 6.4,这对我来说只需 1 行代码就可以完美地工作! https://stackoverflow.com/a/26469607/3634990

self.myBarButtonItem.imageInsets = UIEdgeInsetsMake(0, 25, 0, -25);

请注意,这会移动图像位置,但不会移动触摸区域,因此仅当您想稍微移动图像时,这才是一个很好的解决方案。

关于ios7 - 如何减少 UINavigationBar IOS 7 中 UIBarButton 项目之间的填充?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20537425/

相关文章:

ios - 为 iOS 7 编译的 xcode 6 上的奇怪行为

ios - 导航栏不出现

iphone - 如何将这些左箭头和右箭头添加到我的工具栏?

iOS 自定义字体 "Floats"太高

objective-c - iOS7 - 从 TableView 推送 segue 期间内容重叠

ios - 如何在 iOS7 上更改没有动画的 barTintColor?

ios - 工具栏+导航栏+分段控件?

ios - 当导航栏的颜色在不同的 View Controller 之间发生变化时,如何更改后退按钮的颜色?

iphone - 以编程方式更改 UIBarButtonItem 的标识符属性

ios - 从字典数组中删除键值的重复项