UIBarButtonItem sizes vary

I have an application that uses Storiesboards to display two screens. The first is a list (see Screenshot as "Lista"), and the second is a map ("Térkép"). Each view has a left and right navigation button. Pressing the right button displays the map in the navigation controller. The back button is hidden manually using the map method viewDidLoad .

List viewMap view

The question is, why do bar panel items have a different size on each screen? How can I control the size of the buttons?

The images on the buttons are the same size. Skinning is performed in AppDelegate through appearance settings:

 // navbar background [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"bg-titlebar.png"] forBarMetrics:UIBarMetricsDefault]; // navbar button background [[UIBarButtonItem appearance] setBackgroundImage:[[UIImage imageNamed:@"btn-main.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(4.0, 4.0, 4.0, 4.0) resizingMode:UIImageResizingModeStretch] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; [[UIBarButtonItem appearance] setBackgroundImage:[[UIImage imageNamed:@"btn-main-active.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(4.0, 4.0, 4.0, 4.0) resizingMode:UIImageResizingModeStretch] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault]; // back button background [[UIBarButtonItem appearance] setBackButtonBackgroundImage:[[UIImage imageNamed:@"btn-back.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(4.0, 12.0, 4.0, 4.0) resizingMode:UIImageResizingModeStretch] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; [[UIBarButtonItem appearance] setBackButtonBackgroundImage:[[UIImage imageNamed:@"btn-back-active.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(4.0, 12.0, 4.0, 4.0) resizingMode:UIImageResizingModeStretch] forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault]; 
+8
ios iphone uinavigationbar uibarbuttonitem
source share
1 answer

You can get two identical UIBarButtonsItem by creating them in one session and then copying the button in another segment (at least this works in my case, but I could not determine the root cause of the problem, so far).

If creating the UIBarButtonItem directly does not work, drop the UIButton in the NavigationItem and it will automatically create the UIBarButtonItem with the UIButton inside (see image below). This way you can customize the image or other attributes that are not in the UIBarButtonItem. When you are happy with the appearance of your UIButton (built into the Bar button), copy it to another segment, and they should be the same size.

UIBarButtonItem vs UIButton inside UIBarButtonItem

+1
source share

All Articles