本文介绍了IOS Custom UIBarbuttonItem在详细视图中更改位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自定义导航栏的UIBarbuttonItem,以便我使用此我的Appdelegate.m

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;

}

当我完成时有了这个,我只是将一个UIBarbuttonItem与Storyboard放在一起,我就完成了。
关键是我注意到保存按钮在我的视图之间发生了变化!

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!

看起来好像在我的DetailView中向下移动几个像素:

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

为什么?

推荐答案

我仍然不知道为什么。但我解决了我的自定义UIbarbuttonItem图像30px默认高度。

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

[看到类似的问题UIBarButtonItem在UINavigationController推送后向下移动

[see similar issue UIBarButtonItem shifting downwards after a UINavigationController push

这篇关于IOS Custom UIBarbuttonItem在详细视图中更改位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-09 22:39