UIBarButtonItem Offset? [英] UIBarButtonItem Offset?
问题描述
我试图在我的应用程序中偏移UIBarButtonItems,我需要它们稍微偏移,因为我用于导航栏的图像所以它们都正确排列。我设法这样做:
I am trying to offset the UIBarButtonItems in my app, I need them slightly offset due to the image I use for my navigation bar so it all lines up correctly. I have managed to do this like so:
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:-3 forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundVerticalPositionAdjustment:-3 forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundVerticalPositionAdjustment:-3 forBarMetrics:UIBarMetricsDefault];
我有两个问题。
-
这会停止按钮具有任何突出显示的状态,它们可以正常工作,但不会明显按下。不管怎么说呢?
This stops the buttons have any highlighted state, they function but are no linger visibly pressed down. Anyway around this?
更重要的是,这可以很好地在我的导航栏中将我的按钮向上推,但它会在我的工具栏中将它们推到底部在我需要相反的屏幕,实际上将它们向下推了一下。我该怎么办呢?
More importantly, this works well pushing my buttons upwards in my nav bar, but it pushes them up in my toolbars as well at the bottom of the screen where I need the opposite, actually push them down a little. How can I handle this?
任何帮助总是很感激,谢谢。
Any help always appreciated, thanks.
推荐答案
原来我找到了解决方案!您可以使用以下内容根据对象的视图调整这些外观属性:
Turns out I have found the solution! You can adjust these appearence attributes depending on what view your object is in using the following:
appearanceWhenContainedIn:
而不是标准
appearance
所以我已经实现了我的需求,根据按钮是否调整来上下调整在导航栏或工具栏中:
So I have implemented my needs like so, adjusting up and down depending on if the button is in a nav bar or toolbar:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setBackgroundVerticalPositionAdjustment:-3 forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil] setBackButtonBackgroundVerticalPositionAdjustment:-3 forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class], nil] setBackgroundVerticalPositionAdjustment:3 forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class], nil] setBackButtonBackgroundVerticalPositionAdjustment:3 forBarMetrics:UIBarMetricsDefault];
这篇关于UIBarButtonItem Offset?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!