将可访问性标识符添加到NSMutableAbeatTribedString的子字符串中
我正在尝试在uilabel
's 属于属性属性上配置nsmutableAbeatTributterString
'
目标
uilabel
带有nsattributtedString
具有单击的链接,该链接打开URL,并且- 在链接上具有
appium/voveover可以找到的
accessiencyIdendifier
。
现在正在发生的事情
,链接按预期显示,但是当我使用可访问性检查员查看它们时,它将它们视为一个元素,但是我可以单击链接并按预期打开URL。这是我用来添加链接的扩展程序的实现:
extension NSMutableAttributedString {
@discardableResult
public func setLink(for text: String,
linkURL: String) -> Bool {
guard let url = URL(string: linkURL) else { return false }
let linkRange = self.mutableString.range(of: text)
guard linkRange.location != NSNotFound else { return false }
self.addAttribute(.link,
value: url,
range: linkRange)
// This doesn't do anything :(
self.addAttribute(.accessibilityTextCustom,
value: text,
range: linkRange)
return true
}
}
用法:
private lazy var attributedString: NSMutableAttributedString = {
let string = "CNN and ESPN"
let attributedString = NSMutableAttributedString(string: string)
attributedString.setLink(for: "CNN", linkURL: "https://www.cnn.com")
attributedString.setLink(for: "ESPN", linkURL: "https://www.espn.com")
return attributedString
}()
myLabel.attributedText = attributedString
浏览文档,我看到 AccessibilityLink
,似乎可以完成工作,但它是MacOS 10.4+,而不是iOS。关于如何在appium/convainible Inspector中显示的nsmutableAttributterString
的子字符串上如何获得可访问性标识符的想法?
如果这不是要走的路,是否有办法使用可访问性容器来执行此操作?
I'm attempting to configure a NSMutableAttributedString
on a UILabel
's attributedText
property to display accessibility identifiers for links within the attributed string.
Objective
UILabel
withNSAttributedString
that's got a clickable link which opens a URL and...- Has an
accessibilityIdentifier
on the link that Appium/VoiceOver can find.
What's Happening Now
Right now, the links display as expected, but when I view them with the Accessibility Inspector, it sees them as a single element, however I can click the links and they open the URL as expected. This is the implementation for the extension I'm using to add a link:
extension NSMutableAttributedString {
@discardableResult
public func setLink(for text: String,
linkURL: String) -> Bool {
guard let url = URL(string: linkURL) else { return false }
let linkRange = self.mutableString.range(of: text)
guard linkRange.location != NSNotFound else { return false }
self.addAttribute(.link,
value: url,
range: linkRange)
// This doesn't do anything :(
self.addAttribute(.accessibilityTextCustom,
value: text,
range: linkRange)
return true
}
}
Usage:
private lazy var attributedString: NSMutableAttributedString = {
let string = "CNN and ESPN"
let attributedString = NSMutableAttributedString(string: string)
attributedString.setLink(for: "CNN", linkURL: "https://www.cnn.com")
attributedString.setLink(for: "ESPN", linkURL: "https://www.espn.com")
return attributedString
}()
myLabel.attributedText = attributedString
Looking through documentation, I see accessibilityLink
, which seems like it would get the job done, but it's for MacOS 10.4+, not iOS. Any thoughts on how to get an accessibility identifier on a substring of an NSMutableAttributedString
that shows up in Appium/Accessibility Inspector?
If that's not the way to go, is there a way to do this with an accessibility container?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论