Is it possible to assign an accessibility action to a UILabel?

前端 未结 5 1580
轻奢々
轻奢々 2021-01-18 19:32

In our current UI, next to certain labels, we have a help-tip button that when clicked, explains the details of what the label references. As such, VoiceOver identifies the

5条回答
  •  鱼传尺愫
    2021-01-18 20:03

    Ok, this was easier than I thought. To make a UILabel respond to accessibility actions similar to how a button does, you simply implement a UITapGestureRecognizer. The Accessibility framework uses that just like any other UIView.

        let tapGestureRecognizer = UITapGestureRecognizer(target:self, action:#selector(labelTapped))
        testLabel.userInteractionEnabled = true
        testLabel.addGestureRecognizer(tapGestureRecognizer)
    

    Once you do that, your label will respond to accessibility actions.

提交回复
热议问题