Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIBarButtonItem sizes differ

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];
like image 535
gklka Avatar asked Jun 03 '13 05:06

gklka


1 Answers

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

like image 115
jmg Avatar answered Oct 07 '22 22:10

jmg