禁用时更新UIBarbuttonItem字体 - iOS 11
问题描述:
Upto iOS 10,禁用和启用uibarbuttonitem的字体保持不变,只有颜色不同。但是,我安装我的应用程序在设备上有ios 11后,禁用模式的字体得到更新(显示系统字体),而在启用模式下,它显示了我设置的适当字体。禁用时更新UIBarbuttonItem字体 - iOS 11
因此,对于iOS 11的情况,我如何设置禁用模式的字体以保持应用程序的一致性。
答
这似乎已经在iOS 11中发生了变化,至少在我使用UIAppearance协议的情况下。不知道这是一个错误还是故意。
我也发现我不能掩盖值加在一起(如.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);
}