gpt4 book ai didi

ios - 当 UIAlertController 出现时,UIBarButtonItem 会丢失自定义外观属性

转载 作者:行者123 更新时间:2023-12-02 09:21:23 25 4
gpt4 key购买 nike

我在 UINavigationBar 中有一个 UIBarButtonItem,它具有一些自定义外观属性(自定义字体、颜色)。它通常出现在整个应用程序的大多数地方。

但是,当具有 ActionSheet 样式的 UIAlertController 通过此按钮呈现在 View Controller 上时,BarButton 会丢失其自定义字体外观,导致按钮上出现奇怪的“跳转”并显示不正确的字体,如下所示可以在这里看到:http://giphy.com/gifs/puopiq9mPyI2Q/html5 .

我认为这可能与我们如何设置 BarButton 外观有关,在 AppDelegate 中使用以下代码:

NSDictionary *btnAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor],NSForegroundColorAttributeName,
[AppearanceConstants mediumFontSize20], NSFontAttributeName,nil];
[[UIBarButtonItem appearance] setTitleTextAttributes:btnAttributes forState:UIControlStateNormal];

我的猜测是,栏按钮不在 UIControlStateNormal 中,但是,无论如何,我似乎无法告诉在出现 AlertController 时 BarButton 处于什么状态,并且只是尝试设置标题文本属性为每个控制状态设置适当的值也不起作用。

当我在导航栏中导航到其他带有 BarButtonItems 的 View Controller 时,它们仍然具有正确的外观,并且如果我之后返回到有问题的屏幕,它将具有正确的外观,直到再次呈现 AlertController。

最佳答案

我在呈现 ActionSheet 后重置样式

UIAlertController *alertVC = ... 

[self presentViewController:alertVC animated:YES completion:^{
[self.navigationItem.leftBarButtonItem setDefaultAppearanceForSpecificItem];
[self.navigationItem.rightBarButtonItem setDefaultAppearanceForSpecificItem];
}];

我在 UIBarButtonItem 上创建了一个类别来帮助我

[self setTitleTextAttributes:@{
NSFontAttributeName: [UIFont systemFontOfSize:14],
NSForegroundColorAttributeName: [UIColor VKBlueColor]
}
forState:UIControlStateNormal];

关于ios - 当 UIAlertController 出现时,UIBarButtonItem 会丢失自定义外观属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37014875/

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