How do you set the accessibility label on an image that is drawn with Core Graphics?

廉价感情. 提交于 2021-01-27 15:03:24

问题


I am trying to write UIAutomation tests around some core graphics logic. Currently we are using core graphics to draw an image. I'm trying to set the accessibility label/identifier/value on the image so that I can verify its presence via a UIAutomation test, but no matter what I do I'm not getting the accessibility label/identifier/value on the DOM in my test. Here are the things I have tried:

Setting directly on the image.

UIImage *uiImage = [UIImage imageWithData:bfCaseStudy.image];
uiImage.isAccessibilityElement = YES;
uiImage.accessibilityLabel = bfCaseStudy.name;
uiImage.accessibilityValue = bfCaseStudy.name;
uiImage.accessibilityIdentifier = bfCaseStudy.name;

CGContextDrawImage(context, [self rectForAttr:bfCaseStudy], uiImage.CGImage);

Setting on the Core Image

UIImage *uiImage = [UIImage imageWithData:bfCaseStudy.image];
uiImage.CIImage.isAccessibilityElement = YES;
uiImage.CIImage.accessibilityLabel = bfCaseStudy.name;
uiImage.CIImage.accessibilityValue = bfCaseStudy.name;

CGContextDrawImage(context, [self rectForAttr:bfCaseStudy], uiImage.CGImage);

Either way produces the same result. Here is the UIAutomation code trying to access the information.

UIALogger.logDebug(bookTwoHelper.mainWindow.images()[5].label());
UIALogger.logDebug(bookTwoHelper.mainWindow.images()[5].name());
UIALogger.logDebug(bookTwoHelper.mainWindow.images()[5].value());

Debug: (2013-02-25 16:06:33 +0000) - (null)
Debug: (2013-02-25 16:06:33 +0000) - (null)
Debug: (2013-02-25 16:06:33 +0000) - (null)

Here is the relevant portion of the DOM

UIAImage "(null)" {{0, 149}, {316, 55}}

Is there a way to set an accessibility label/identifier/value on an image that is drawn using core graphics?


回答1:


Properties like accessibilityLabel will only work when used with UIKit controls like UIView, UIImageView etc. Because your image isn't a real UIView, you will need to provide extra information to UIKit by making your container view or view controller implement the UIAccessibilityContainer protocol.

See the Accessibility Programming Guide for iOS for more information, particularly Make the Contents of Custom Container Views Accessible.



来源:https://stackoverflow.com/questions/15071984/how-do-you-set-the-accessibility-label-on-an-image-that-is-drawn-with-core-graph

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