8
votes

I have an app, which uses Storyboards to display two screens. The first one Is a list (referred on screenshot as "Lista"), and the second one is a map ("Térkép"). Each view has a left- and a right navigation button. Pressing the right button pushes the map view to the Navigation Controller. The back button is hidden manually from the map's viewDidLoad method.

List viewMap view

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

The images on the buttons are in the same size. Skinning is done 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];
1
well in my case this formula always has worked for me. May be you are giving bounds to your bar button separately or there should be some orientation issue. - Jogi Thakur
Questions with images are always appreciated :) - Anupdas
Try setting the buttons in the viewWillAppear if you are currently using the viewDidLoad - Mark McCorkle
The buttons have been set up in the Storyboard. - gklka

1 Answers

1
votes

You can get two identical UIBarButtonsItem by creating it in one segue and then copy-pasting the button in another segue (at least this is working in my case but I haven't been able to identify the root cause of the problem so far).

If creating directly a UIBarButtonItem is not working, drop a UIButton in the NavigationItem and it will create automatically a UIBarButtonItem with a UIButton inside (see below image). In this way you can configure an image or other attributes not present in a UIBarButtonItem. Once you are happy with the appearance of your UIButton (embedded in the Bar Button), copy paste it to a different segue and they should keep the same size.

UIBarButtonItem vs UIButton inside UIBarButtonItem