AccessibilityHint for Back Button in Navigation Controller for VoiceOver

岁酱吖の 提交于 2019-12-20 04:10:51

问题


Is there any way to set accessibilityHint for back button? I would like that voiceover read first

"Back Button" and after this Hint e.g. "Double tap to go back to select a building screen"

I'm trying to do it that way but it's not working:

in viewDidLoad:

[super viewDidLoad];
// back button without any text just back arrow
UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@""
                                                                      style:UIBarButtonItemStylePlain
                                                                     target:nil
                                                                     action:nil];

self.navigationItem.backBarButtonItem = backBarButtonItem;
self.navigationItem.backBarButtonItem.accessibilityHint = @"Double tap to go back to select a building screen";

回答1:


Just set accessibility label and not accessibility hint.

self.navigationItem.backBarButtonItem.accessibilityLabel = @"Back Button, Double tap to go back to select a building screen";




回答2:


Instead of using backBarButtonItem, use of leftBarButtonItem should be the trick.

Try the code below in your view controller that displays the back button :

override func viewDidLoad() {
    super.viewDidLoad()

    let myBackButton = UIBarButtonItem(image: UIImage(named: "chevron"), 
                                       style: .done, 
                                       target: self, 
                                       action: #selector(goBackToThePreviousView(info:)))

    myBackButton.accessibilityLabel = "this is the back button"
    myBackButton.accessibilityHint = "this is my personal hint"

    self.navigationItem.leftBarButtonItem = myBackButton
}

Now, you have only an arrow for the back button and you can add whatever desired accessibility label or hint.



来源:https://stackoverflow.com/questions/29623904/accessibilityhint-for-back-button-in-navigation-controller-for-voiceover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!