作者:萌星 | 来源:互联网 | 2023-01-16 17:15
在iOS 10中,禁用和启用uibarbuttonitem的字体保持不变,只有颜色不同.但是,在我在具有ios 11的设备上安装我的应用程序后,禁用模式的字体会更新(显示系统字体),而在启用模式下,它显示我设置的正确字体.
因此,对于iOS 11的情况,我如何设置禁用模式的字体以保持应用程序的一致性.
1> SeanR..:
这似乎在iOS 11中有所改变,至少在我使用UIAppearance协议的情况下.不确定这是一个bug还是故意的.
我还发现我无法将值掩盖在一起(例如.normal|.disabled
),因为它意味着如果控件满足所有状态,它将仅应用字体.
所以我最终这样做了:
for controlState in [UIControlState.normal, UIControlState.disabled, UIControlState.focused, UIControlState.highlighted, UIControlState.selected] {
barButton.setTitleTextAttributes([NSFontAttributeName: customFontName], for: controlState)
}
使用UIAppearance协议在任何地方更新它:
for controlState in [UIControlState.normal, UIControlState.disabled, UIControlState.focused, UIControlState.highlighted, UIControlState.selected] {
UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: customFontName, for: controlState);
}