简体   繁体   中英

Control UIBarButtonItem resizing iOS 7

I have a navigationBar set up with an image for titleView as well as a leftBarButtonItem and a rightBarButtonItem.

The problem is that when I change the title of the leftBarButtonItem to a wider one it causes the titleView to jump a couple of pixels to the right.

So how can I control the resizing behaviour of barButtonItems?

My code where I create the buttons and image:

UIImage *navBarTitleImage = [UIImage imageNamed:@"header_icon.png"];
self.navigationItem.titleView = [[UIImageView alloc] initWithImage:navBarTitleImage];

UIBarButtonItem *unitButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Metric", nil) style:UIBarButtonItemStylePlain target:self action:@selector(changeUnits)];
self.navigationItem.leftBarButtonItem = unitButton;

UIBarButtonItem *resetButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Reset", nil) style:UIBarButtonItemStylePlain target:self action:@selector(resetValues)];
self.navigationItem.rightBarButtonItem = resetButton;

Any help would be very appreciated!

如果按钮在一段时间内将有多个标题,请设置其widthpossibleTitles标题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM