对于符合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;
我从未找到任何按钮
欢迎您的帮助
答案 0 :(得分:0)
Thanks to Joanna Carter from french website Cocoacafe.fr
解决方案:
@IBOutlet weak var searchBar: UISearchBar!
override func viewDidLoad()
{
super.viewDidLoad()
for subView in searchBar.subviews
{
for sView in subView.subviews
{
if let textField = sView as? UITextField,
let clearButton = textField.valueForKey("clearButton") as? UIButton
{
clearButton.isAccessibilityElement = true
clearButton.accessibilityLabel = NSLocalizedString("Clear Text", comment: "")
}
}
}
}