简体   繁体   中英

IOS Custom UIBarbuttonItem change position in detail view

I'm trying to customize my navigationbar's UIBarbuttonItem so that I'm using this im my Appdelegate.m

// didFinishLaunchingWithOptions: 

{
  UIImage *navBarImage = [UIImage imageNamed:@"nav-bar.png"];

  [[UINavigationBar appearance] setBackgroundImage:navBarImage
                                   forBarMetrics:UIBarMetricsDefault];

  [[UINavigationBar appearance] setTitleVerticalPositionAdjustment:5
                                                   forBarMetrics:UIBarMetricsDefault];



  UIImage *barButtonSave = [[UIImage imageNamed:@"nav-bar-button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 2, 0, 2)];


[[UIBarButtonItem appearance] setBackgroundImage:barButtonSave
                                        forState:UIControlStateNormal
                                           style:UIBarButtonItemStyleDone
                                      barMetrics:UIBarMetricsDefault];

[[UIBarButtonItem appearance] setBackgroundVerticalPositionAdjustment:5 forBarMetrics:UIBarMetricsDefault];


return YES;

}

When I'm done with this I just place a UIBarbuttonItem with Storyboard and I'm done. The point is I noticed that the "Save" button changes between my views!

It looks like is moving down few pixels in my DetailView:

在此处输入图片说明

Why is That?

I still don't know why. but I solved giving my custom UIbarbuttonItem image the 30px default height.

[see similar issue UIBarButtonItem shifting downwards after a UINavigationController push

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