
I am trying to reduce the distance between these two button elements.
I use
navigationItem setRightBarButtonItems
to set two button elements, but they are too far apart.
I tried to add a negative space, I tried to add a spacer after it, a fixed space, a flexible space. You don't see anything in the docs that say you cannot change the interval, but I cannot find it.
Thanks for the help in advance.
CHANGE AFTER ANSWER:
Siu Chung Chan's answer was absolutely correct, but since I did not receive it at first, I thought I would share a code that made me realize that he was right.
If you placed all this in one block, it would look like his (very correct) answer:
UIView *filterBtnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)]; UIButton *filterBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)]; [filterBtn addTarget:self action:@selector(someMethod) forControlEvents:UIControlEventTouchUpInside]; [filterBtn setBackgroundImage:[UIImage imageNamed:@"someicon"] forState:UIControlStateNormal]; [filterBtnView addSubview:filterBtn]; UIBarButtonItem *btnFilter = [[UIBarButtonItem alloc] initWithCustomView:filterBtnView]; UIView *selectBtnView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)]; UIButton *selectBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)]; [selectBtn setBackgroundImage:[UIImage imageNamed:@"someothericon"] forState:UIControlStateNormal]; [selectBtn addTarget:self action:@selector(someOtherMethod:) forControlEvents:UIControlEventTouchUpInside]; [selectBtnView addSubview:selectBtn]; UIBarButtonItem *btnSelect = [[UIBarButtonItem alloc] initWithCustomView:selectBtnView]; [self.navigationItem setRightBarButtonItems:@[btnFilter, btnSelect] animated:YES];
For me, the beauty of this is that it looks at how some of the opinions are actually set by Apple to be biased about how they wanted to use them only. Therefore, if you want to create a highly customizable user interface, you need to do a lot of manipulation with UIView to get around their (possibly) unintended barriers.
The moral of the story: if the view is not suitable for you, try to recreate the view from the UIView level and then add it to the view that you want to display.
Thanks again Siu Chung Chan!