作者:翔云飘雪9_694_492 | 来源:互联网 | 2023-01-21 12:42
我一直在使用此代码来更改导航栏中元素的色调:
UINavigationBar.appearance().tintColor = theme.labelColor
但是,这不再适用于iOS 11.在iOS 11之前,导航栏中的按钮是UINavigationButton
s,但在iOS 11中它们已被更改为_UIModernBarButton
.我能够改变它们的色调颜色UIButton.appearance().tintcolor
,但这会改变每个按钮的颜色.
这是一个比较:
任何人都知道如何更改导航栏中的按钮色调颜色?
更新01/09/2017:
看起来_UIButtonBarButton
有正确的色调颜色,但_UIModernBarButton
用颜色设置覆盖它UIButton
.
更新18/09/2017:
"工程部就此问题提供了以下反馈:
UIView.tintColor不是外观选择器,特别是由于其继承属性而被记录为不能正常作为外观属性."
1> dehlen..:
所以我确实找到了一种解决方案.我通过UIButton的外观代理设置色调颜色,但仅限于包含在UINavigationBar中.这看起来对我有用.但是仍然希望这种行为会在iOS 11 GM中发生变化,或者有人可以提出更好的解决方案.这是我的工作代码:
if([UIButton respondsToSelector:@selector(appearanceWhenContainedInInstancesOfClasses:)]) {
[[UIButton appearanceWhenContainedInInstancesOfClasses:@[UINavigationBar.class]]setTintColor:navTintColor];
}
Swift版本的外观代理调用:
UIButton.appearance(whenContainedInInstancesOf: [UINavigationBar.self]).tintColor = UIColor.red