gpt4 book ai didi

ios - 在 UINavigationBar 中将位置更改为更靠近 rightBarButtonItem 的右侧

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

这是我的代码

- (void)createCustomBtnRightBar:(UIImage *)buttonImage
{
self.navigationItem.rightBarButtonItem = nil;
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
if (buttonImage != nil) {
[button setImage:buttonImage forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 45, 33);
button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, -10);
} else {
[button setTitle:@"Add New Pal" forState:UIControlStateNormal];
button.frame = CGRectMake(0, 0, 110, 24);
[button.titleLabel setTextAlignment:NSTextAlignmentRight];
}

[button addTarget:self action:@selector(onClickBtnSendClip:) forControlEvents:UIControlEventTouchUpInside];
[button setBackgroundColor:[UIColor greenColor]];

//create a UIBarButtonItem with the button as a custom view
UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithCustomView:button];

self.navigationItem.rightBarButtonItem = customBarItem;
}

enter image description here

当改变宽度为200

enter image description here

当添加button.titleEdgeInsets = UIEdgeInsetsMake(0, 20, 0, 0);

enter image description here

In all these cases, the area of the right can not move

我需要这样的东西。

enter image description here

我什至尝试过这个

UIBarButtonItem *customBarItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
customBarItem.customView = button;

但确实崩溃了

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Fixed and flexible space items not allowed as individual navigation bar button item. Please use the rightBarButtonItems (that's plural) property.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001132a2e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000112d19deb objc_exception_throw + 48
2 CoreFoundation 0x00000001132a2d9d +[NSException raise:format:] + 205
3 UIKit 0x000000011156d560 -[UINavigationItem setRightBarButtonItem:animated:] + 131
4 sdsd sdsdsd 0x000000010e042dd3 -[SendClipViewController createCustomBtnRightBar:] + 1475

Worked perfect before when I was the button bar direct from the story board and space on the right was smaller (as I need).

enter image description here

如有任何帮助,我们将不胜感激。谢谢

最佳答案

您需要使用 .Fixed Space 来实现:

UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSpacer.width = -10;
self.navigationItem.rightBarButtonItems = @[negativeSpacer, customBarItem];

关于ios - 在 UINavigationBar 中将位置更改为更靠近 rightBarButtonItem 的右侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35775351/

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