gpt4 book ai didi

ios - 禁用时更新 UIBarbuttonItem 字体 - iOS 11

转载 作者:可可西里 更新时间:2023-11-01 03:08:43 25 4
gpt4 key购买 nike

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

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

最佳答案

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

我还发现我无法将值一起屏蔽(例如 .normal|.disabled),因为这意味着它只会在控件满足所有时应用字体州。

所以我最终这样做了:

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

使用 UIAppearance 协议(protocol)在任何地方更新它:

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

关于ios - 禁用时更新 UIBarbuttonItem 字体 - iOS 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46426051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com