gpt4 book ai didi

ios - 如何更改导航栏按钮之间的距离

转载 作者:行者123 更新时间:2023-11-28 21:54:51 33 4
gpt4 key购买 nike

我设置了两个导航栏按钮,中间有一个空格,如何改变这个空格,让按钮靠得更近一些?我试图添加第三个宽度为负的按钮,这里是代码

self.editButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Edit.png"] style:UIBarButtonItemStylePlain target:self action:@selector(editAction:)];
self.callButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"call_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(editAction:)];
UIBarButtonItem *spacer = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:nil] style:UIBarButtonItemStylePlain target:self action:nil];
spacer.width = -30;

NSArray *buttons = @[self.editButton, spacer, self.callButton];
self.navigationItem.rightBarButtonItems = buttons;

但是它不起作用;有什么建议吗?

最佳答案

UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = -16;// it was -6 in iOS 6
[self.navigationItem rightBarButtonItems:[NSArray arrayWithObjects:negativeSpacer, requriedButton/*this will be the button which u actually need*/, nil] animated:NO];

希望这对你有用...

关于ios - 如何更改导航栏按钮之间的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26926601/

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