禁用时更新UibarbuttonItem字体-IOS 11



在iOS 10中,禁用和启用的uibarbuttonitem的字体保持不变,只有颜色不同。但是,在我在具有iOS 11的设备上安装应用程序后,禁用模式的字体会更新(显示系统字体),而在启用模式下,它显示了我设置的正确字体。

因此,对于iOS 11的情况,如何为禁用模式设置字体以保持应用程序的一致性。

这似乎在iOS 11中发生了变化,至少在我使用uiappearance协议的情况下。不确定这是错误还是故意。

我还发现我无法将值掩盖在一起(例如.normal|.disabled),因为它仅在满足所有 all 状态时才应用字体。

所以我最终这样做了:

for controlState in [UIControlState.normal, UIControlState.disabled, UIControlState.focused, UIControlState.highlighted, UIControlState.selected] {
    barButton.setTitleTextAttributes([NSFontAttributeName: customFontName], for: controlState)
}

使用UIAPPERANCE协议到处更新它:

for controlState in [UIControlState.normal, UIControlState.disabled, UIControlState.focused, UIControlState.highlighted, UIControlState.selected] {
    UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: customFontName, for: controlState);
}

最新更新