呈现 UIAlertController 时,UIBarButtonItem 丢失自定义外观属性
UIBarButtonItem loses custom appearance attributes when UIAlertController is presented
我在 UINavigationBar 中有一个 UIBarButtonItem,它具有一些自定义外观属性(自定义字体、颜色)。它通常出现在整个应用程序的大多数地方。
但是,当使用此按钮在视图控制器上显示具有 ActionSheet 样式的 UIAlertController 时,BarButton 会失去其自定义字体外观,导致按钮看起来很奇怪 "jump" 并且字体不正确显示,如下所示: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 时条形按钮处于什么状态,并且只是试图设置标题将文本属性设置为每个控件状态的适当值也不起作用。
执行此操作后,当我导航到其他在其 NavigationBar 中使用 BarButtonItems 的视图控制器时,它们仍然具有正确的外观,如果我之后返回到有问题的屏幕,它将具有正确的外观,直到再次显示 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];
我在 UINavigationBar 中有一个 UIBarButtonItem,它具有一些自定义外观属性(自定义字体、颜色)。它通常出现在整个应用程序的大多数地方。
但是,当使用此按钮在视图控制器上显示具有 ActionSheet 样式的 UIAlertController 时,BarButton 会失去其自定义字体外观,导致按钮看起来很奇怪 "jump" 并且字体不正确显示,如下所示: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 时条形按钮处于什么状态,并且只是试图设置标题将文本属性设置为每个控件状态的适当值也不起作用。
执行此操作后,当我导航到其他在其 NavigationBar 中使用 BarButtonItems 的视图控制器时,它们仍然具有正确的外观,如果我之后返回到有问题的屏幕,它将具有正确的外观,直到再次显示 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];