gpt4 book ai didi

iOS 7 UIBarButtonItem 荒谬的间距问题

转载 作者:可可西里 更新时间:2023-11-01 03:11:31 25 4
gpt4 key购买 nike

我有一个问题,到目前为止我找不到解决方案。我正在向我的应用程序添加一个新功能,并希望在我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com