Join Jon Bott for an in-depth discussion in this video Accessibility Inspector, part of Xcode Developer Tools in iOS.
- [Instructor] First, let's take a look at the Accessibility Inspector. You can access this by clicking on Xcode, Open Developer Tool, Accessibility Inspector. Let's click back on to Xcode and run the application. After the application has launched, we can come over here and select the Simulator as our target, and you can click on this target reticle, which will allow you to choose different accessibility points.
In this case, it's going to be a table row, and you can even navigate to the next element by using the arrows. In this case, it'll be an image, but we can't continue beyond that, and that's because there's a bug that's been around since Xcode 8, and has not been fixed all the way up to Xcode 9.2, so we have to find another way to make it so that we can use these accessible elements. A place for us to look at is the main storyboard first.
Let's go ahead and just move this panel, and when we select these elements, you can see, over on the right, that the accessibility is enabled, but it doesn't actually do anything. We have to set the accessibility of these elements, programmatically. So, the first place to go is the actual cell, and in here, let's go ahead and collapse the panels, and we'll just come down to here, and we're going to make a method in our commonInit, and we'll call it setAccessibilityProperties(), and then we'll actually make that function, and in here, we're going to set the accessibility value for the passwordLabel and the passwordValue label.
So we will say passwordLabel.isAccessibilityElement = true, and then passwordValue.isAccessibilityElement = true. That's all we have to do to start this, so let's go ahead and build and run this, and I'll bring that Inspector back over, and now, we can click the target reticle, and you can see we can actually access these other elements, we should be able to target again, click the image, and navigate through them, just as if we were using some of the settings on the phone to help us with accessibility.
So, now that we've got things working, our labels are actual elements, we can come into here on the next tab over, the Audit tab, and we will be able to run an audit on this. This'll tell us everything that we are missing in order to have this a full accessible application. In this case, we have a couple of issues. First, the element has no description. If you aren't sure what that means, you can click on this question mark, and it'll say considering setting the accessibility label on it. So let's go do that first for this CustomCell.
We'll go to the actual storyboard, and pull up this panel, I'll move the Accessibility panel away, and in here, we have a label. In this case, I'll just name it Spy Image, I'll come to the password, it'll infer the values on these for our text fields, but I'll put an actual thing Password Label, and this one I will say, Password Text, or a Value might be better, and now, I can run this again, I'll go ahead and clear out those results, and run the audit again, and the last thing that it says is we don't have dynamic text font sizes for these different text fields, and that's a larger topic for us to talk about in the next video.
- Working with the Accessibility Inspector
- Reviewing dynamic text and audit fixes
- Using the Memory Debugger
- Using the Thread Sanitizer
- Debugging view hierarchies
- Analyzing a project for memory consumption