嗨,很棒的 SO 社区。p>
我一直在努力改变或禁用 UISearchBar 处理可访问性的方式。我正在开发一个应用程序,它需要 UISearchBar、范围按钮文本、光标、占位符等来保持相同的大小,尽管增加了辅助功能字体设置。我知道你们中的许多人可能会说“确保视图相应地响应可访问性”,我同意。但这是一个特定的用例。
如果用户在辅助功能设置中最大化了字体大小,UISearchBar 及其中的所有内容都需要基本上忽略增加的字体大小。我尝试了很多事情(包括疯狂的挣扎)。即
guard let searchField = searchBar.value(forKey: "searchField") as? UISearchTextField else { return }
searchField.isAccessibilityElement = false
searchField.adjustsFontForContentSizeCategory = false
或:
// access the scopebutton textfield.
if let textField: UITextField = self.searchBar?.value(forKey: "Physical") as? UITextField {
textField.adjustsFontForContentSizeCategory = false
}
我可以改变条的颜色,没问题。
if #available(iOS 13.0, *) {
self.searchBar.searchTextField.backgroundColor = UIColor.blue
self.searchBar.searchTextField.adjustsFontForContentSizeCategory = false
} else {
// Fallback on earlier versions
};
我研究了有关 UISearchBar 辅助功能的 Apple 文档,但似乎没有为该视图提供许多辅助功能选项。任何帮助将不胜感激。
如果我找到解决方案,我会继续研究和尝试并更新。
谢谢大家!