IOS Custom UIBarbuttonItem change position in detail view

偶尔善良 提交于 2019-12-11 01:24:49

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/15545051/ios-custom-uibarbuttonitem-change-position-in-detail-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!