iOS 7 UIBarButtonItem 荒谬的间距问题

标签 ios ios7 uinavigationbar uibarbuttonitem spacing

我有一个问题,到目前为止我找不到解决方案。我正在向我的应用程序添加一个新功能,并希望在我的 UINavigationBar 的左侧添加第二个 UIBarButtonItem。由于某种原因,iOS 7 将其作为 button1、grandCanyon、button2。我找不到任何方法来消除这两个按钮之间的荒谬间距,这也导致我的标题不对齐。谁能帮忙!?有解决办法吗!?

enter image description here

代码:

UIBarButtonItem *firstButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"firstButton"] style:UIBarButtonItemStylePlain target:self action:@selector(showSettings)];
UIBarButtonItem *secondButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"secondButton"] style:UIBarButtonItemStylePlain target:self action:@selector(showAttachments)];
[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObjects:firstButton, secondButton, nil]];

最佳答案

我认为我已经使用自定义 View 解决了问题,如下所示,它并不完美(例如,选择使按钮变暗而不是变暗),但我会在明天尝试解决这个问题。很高兴我的头痛已经过去了!感谢您的帮助,它让我找到了一些我没有尝试过的新方法。

UIImage *firstButtonImage = [UIImage imageNamed:@"firstButton"];
firstButtonImage = [firstButtonImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

UIButton *firstButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
[firstButton setImage:firstButtonImage forState:UIControlStateNormal];
[firstButton addTarget:self action:@selector(firstButtonPressed) forControlEvents:UIControlEventTouchUpInside];

UIImage *secondButtonImage = [UIImage imageNamed:@"secondButton"];
secondButtonImage = [secondButtonImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

UIButton *secondButton = [[UIButton alloc] initWithFrame:CGRectMake(45, 0, 35, 35)];
[secondButton setImage:secondButtonImage forState:UIControlStateNormal];
[secondButton addTarget:self action:@selector(secondButtonPressed) forControlEvents:UIControlEventTouchUpInside];

UIView *leftBarItemsView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 80, 35)];
[leftBarItemsView addSubview:firstButton];
[leftBarItemsView addSubview:secondButton];

UIBarButtonItem *leftBarItem = [[UIBarButtonItem alloc] initWithCustomView:leftBarItemsView];

[self.navigationItem setLeftBarButtonItems:[NSArray arrayWithObject:leftBarItem]];

关于iOS 7 UIBarButtonItem 荒谬的间距问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19306495/

相关文章:

iOS:删除 UINavigationBar 动画

ios - 更改 ios 应用程序下方标签栏的高度和设计

ios - 每个 iCloud 用户如何在 CloudKit 中保存用户特定的订阅?

iOS NSInputStream

ios - 使用 DarkMode,触摸时不会选择单元格的 ContentView,仅选择 AccessoryView

ios - 从 CABasicAnimation 转换代码

iOS 7 MPVolumeView 改变大小

ios - 我要如何给我的 friend 一份 iOS 7 的 Beta 测试我的应用程序?

c# - 在 UINavigationBar 中将图像左对齐

ios - 使用 iTunes Analytics 跟踪 Facebook 应用安装广告的转化