UINavigationBar-更改UIBarButtonItem位置 [英] UINavigationBar - change UIBarButtonItem positions
问题描述
我在我的应用程序中使用UINavigationController及其栏. 现在,我想更改leftBarButtonItem和rightBarButtonItem的位置. 我希望它们位于具有自定义高度和高度的不同x和y位置.
I am using a UINavigationController and its bar within my app. Now I want to change the leftBarButtonItem and rightBarButtonItem positions. I want them to be on a different x and y position having a custom witdth and height.
但是问题是,使用barButtonItem更改框架不会更改任何内容.我现在不为什么,但是框架始终会重置为其原始坐标.
But the problem is, that changing the frame does not change anything with the barButtonItem. I do not now why, but the frame always gets resetted to its original coordinates.
这是我在viewWillAppear中调用的代码:
Here is my code which I call in viewWillAppear:
UINavigationItem *navItem = [[self.navigationBar items] lastObject];
UIView *rightview = [[UIView alloc] initWithFrame:CGRectMake(0,0,66,30)];
rightview.backgroundColor = [UIColor blueColor];
//add custom view
UIBarButtonItem *search = [[UIBarButtonItem alloc] initWithCustomView:rightview];
navItem.leftBarButtonItem = search;
视图不是从0/0开始,例如x位置是在5px insetead 0处.
The view is not starting at 0/0, the x position for example is at 5px insetead of 0.
关于如何解决此问题的任何建议?
Any suggestions on how to solve this issue?
推荐答案
我认为您没有能力移动UIBarButtonItem
,但是通过将UIView
元素添加为子视图,您也许可以达到相同的效果导航栏(或navItem
).您需要稍微玩一下.它应该允许更大的灵活性.
I dont think you have the ability to move a UIBarButtonItem
but you might be able to achieve the same effect by adding that UIView
element as a subview to the navigationBar (or navItem
). You'll need to play with it a bit. It should allow for much more flexibility.
希望这会有所帮助.
这篇关于UINavigationBar-更改UIBarButtonItem位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!