对于符合UIAccessibility和VoiceOver的个人应用程序,我需要更改UISearchBar中的明文按钮(灰色十字)的UIAccessibilty标签。
我不知道如何访问这个元素。
我试着
class ViewController: UIViewController, UISearchBarDelegate
{
@IBOutlet weak var searchBar: UISearchBar!
weak var btnCancel: UIButton?
override func viewDidLoad()
{
super.viewDidLoad()
for subView in searchBar.subviews
{
for subSubView in subView.subviews
{
if subSubView.isKindOfClass(UIButton)
{
btnCancel = subSubView as? UIButton
btnCancel?.isAccessibilityElement = true
btnCancel?.accessibilityLabel = NSLocalizedString("Clear Text", comment: "")
}
}
}
}
}
我在viewDidLoad上试了一下;searchBar textDidChange ;searchBarTextDidBeginEditing ;
我从来没找到什么纽扣
欢迎你的帮助
2条答案
按热度按时间xxls0lw81#
Thanks to Joanna Carter from french website Cocoacafe.fr
解决方案:
pepwfjgg2#
如果let searchTextField = self.searchBar.value(forKey:“searchField”)作为?UITextField,让clearButton = searchTextField.value(forKey:“clearButton”)as?UIButton { clearButton.isAccessibilityElement = true clearButton.tintColor = .red clearButton.accessibilityLabel = NSLocalizedString(“Clear Button accessibility labe;“,评论:“”)}