gpt4 book ai didi

xcode - 如何删除 UIBarButtonItem 旁边的填充

转载 作者:行者123 更新时间:2023-12-04 16:26:17 25 4
gpt4 key购买 nike

我在导航栏的自定义右侧栏按钮项中添加了一个自定义按钮,如图所示。

我希望能够删除按钮后的空间,使其接触屏幕的右边缘,但即使在搜索后也找不到解决方案。如果有人能提到如何,那就太好了。

这是我正在使用的代码

UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];    
aButton.frame = CGRectMake(50.0, 0.0, 60, 44);
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];
[aButton addTarget:self action:@selector(testButtonControl:) forControlEvents:UIControlEventTouchUpInside];

self.navigationItem.rightBarButtonItem = aBarButtonItem;

enter image description here

最佳答案

你可以添加一个负宽度的固定空间元素(我知道,这听起来像一个黑客,但它有效):

UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];    
aButton.frame = CGRectMake(50.0, 0.0, 60, 44);
UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:aButton];
[aButton addTarget:self action:@selector(testButtonControl:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *spaceFix = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:NULL];
spaceFix.width = -5;

self.navigationItem.rightBarButtonItems = @[spaceFix, aBarButtonItem];

关于xcode - 如何删除 UIBarButtonItem 旁边的填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11814983/

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