Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you implement the UIAccessibility protocol?

The "Accessibility Programming Guide For iOS" states:

Another way is to implement the isAccessibilityElement method of the UIAccessibility protocol in the implementation of your custom subclass. The following code snippet shows how to do this:

But when I am doing so, as in the following code:

class UITextLayerLabel : UIView, UIAccessibility {

XCode returns me this error:

 [...] Use of undeclared type 'UIAccessibility'

What I am missing? A specific import? Is the protocol still available with iOS 10/XCode8?

like image 792
yves Baumes Avatar asked Jul 05 '26 15:07

yves Baumes


1 Answers

As pointed out here, UIAccessibility is an informal protocol. For the difference between an informal protocol and a formal one, see here.

Basically, there is no type called UIAccessibility. Actually, UIView is already conforming to UIAccessibility. To make your custom view accessible, just override the properties and methods starting with accessibility.

So when do you need to implement UIAccessibility? As stated here,

You can use UIAccessibilityElement to provide information about an icon or text image is not automatically accessible because it does not inherit from UIView (or UIControl ). A view that contains such nonview items creates an instance of UIAccessibilityElement to represent each item that needs to be accessible.

like image 101
Sweeper Avatar answered Jul 07 '26 07:07

Sweeper