1

In iOS, how to set accessibility focus to a button through programmatically?

Cœur
  • 37,241
  • 25
  • 195
  • 267
sush
  • 11
  • 1
  • 2

3 Answers3

0

You can do this via following notifications:

UIAccessibilityLayoutChangedNotification

or

UIAccessibilityScreenChangedNotification

E.g.

UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, yourElement);
Rahil Wazir
  • 10,007
  • 11
  • 42
  • 64
ClemensL
  • 404
  • 2
  • 10
0

@ClemensL response works great. Here is a Swift 5 version:

func setAccessibilityFocus() {
    UIAccessibility.post(notification: UIAccessibility.Notification.layoutChanged, argument: self)
}
Sebbo
  • 326
  • 4
  • 10
-1

You can set focus to any UI element by using the following snippet.

UIAccessibility.setFocusTo(your-UI-element)

Govind
  • 84
  • 7