问题
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