gpt4 book ai didi

iphone - 使用 UIAppearance 时 UIBarButtonItem 的奇怪行为

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:31:12 26 4
gpt4 key购买 nike

我正在使用 UIAppearance 自定义导航栏、选项卡栏和 uibarbuttonitem 等元素。除了 UIBarButtonItem 元素的非常奇怪的行为外,它工作得很好。在导航 Controller 层次结构的顶层,一切看起来都不错,但如果我按下下一个 View Controller ,UIBarButtonItem 元素会稍微向下移动一点,但与此同时,后退按钮会保持在正确的位置。我附上了两张图片来说明我的问题。

1) 导航 Controller 层次结构中的第一个 View Controller

enter image description here

2) 导航 Controller 层次结构中的第二个 View Controller

enter image description here

编辑:代码

    //Change navigation bar appearance
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"GPNavigationBarBackground.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[[UIImage alloc] init]];
[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:@"GPNavigationBarShadow.png"]];

[[UINavigationBar appearance] setTitleTextAttributes:
[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[UIFont boldSystemFontOfSize:17], UITextAttributeFont,nil]];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:2.f forBarMetrics:UIBarMetricsDefault];

UIImage *buttonBackground = [[UIImage imageNamed:@"GPNavigationBarButton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)];
UIImage *buttonPressedBackground = [[UIImage imageNamed:@"GPNavigationBarButtonPressed.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 10, 0, 10)];

UIImage *backButtonBackground = [[UIImage imageNamed:@"GPNavigationBarBackButton.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 10)];
UIImage *backButtonPressedBackground = [[UIImage imageNamed:@"GPNavigationBarBackButtonPressed.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 15, 0, 10)];

[[UIBarButtonItem appearance] setBackgroundImage:buttonBackground forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundImage:buttonPressedBackground forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonBackground forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonPressedBackground forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];

[[UIBarButtonItem appearance] setBackButtonBackgroundVerticalPositionAdjustment:1.f forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundVerticalPositionAdjustment:1.f forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, 1.f) forBarMetrics:UIBarMetricsDefault];

最佳答案

好吧,经过我对那个问题的思索,我终于解决了它。上面的代码是完全正确的。唯一的问题是 UIBarButtonItem 的背景图像的高度。 UIAppearance 代理允许您设置所有图形,但不允许您更改 UIBarButtonItem 的高度。

So, when customizing UIBarButtonItem, always remember that a UIBarButtonItem can't be higher than 30pt. That means that custom artwork shouldn't exceed this size.

你可以设置高于30pt的背景图片,但你会遇到与上述相同的问题。

关于iphone - 使用 UIAppearance 时 UIBarButtonItem 的奇怪行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14324859/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com