IOS 7 UIBarButtonFamous funny question about distance

I have a problem that so far I can’t find a solution. I am adding a new function to my application and want to add a second UIBarButtonItem on the left side of my UINavigationBar. For some reason, iOS 7 accepts this as button1, grandCanyon, button2. I cannot find a way to remove the ridiculous distance between the two buttons, which also leads to my heading not aligning. Can someone help !? Is there a solution to this ??

enter image description here

the code:

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]]; 
+8
ios ios7 uinavigationbar uibarbuttonitem spacing
source share
2 answers

I think I managed to deal with the problem using a custom view, as shown below, this is not ideal (the choice darkens the buttons darker than lighter, for example), but I will try to fix it tomorrow. Just glad my headache is over! Thanks for your help, this led me to several new approaches that I have not tried.

 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]]; 
+4
source share

There may be a better way, but to fix interpolation issues on button bar items on iOS 7, I subclassed the UINavigationBar and redefined the layoutSubviews method. There you can move every element of the panel button wherever you want.

As an example:

 - (void)layoutSubviews { [super layoutSubviews]; // If iOS 7, fix the bar button positions BOOL isIOS7 = [[[UIDevice currentDevice] systemVersion] compare:@"7" options:NSNumericSearch] != NSOrderedAscending; if (isIOS7) { for (UIBarButtonItem *item in self.topItem.leftBarButtonItems) { // Reposition the customView property } for (UIBarButtonItem *item in self.topItem.rightBarButtonItems) { // Reposition the customView property } } } 

Actually, when I looked at my code, I used UIBarButtonItems with custom views. Thus, I was able to move the user position of the view.

You will most likely have to iterate over the subviews of the UINavigationBar to move them if you just use UIBarButtonItems with these images:

 - (void)layoutSubviews { [super layoutSubviews]; // If iOS 7, fix the bar button positions BOOL isIOS7 = [[[UIDevice currentDevice] systemVersion] compare:@"7" options:NSNumericSearch] != NSOrderedAscending; if (isIOS7) { for (UIView *subview in self.subviews) { // Reposition as needed } } } 
+2
source share

All Articles