【问题标题】:iPhone - make VoiceOver announce label text changeiPhone - 让 VoiceOver 宣布标签文本更改
【发布时间】:2011-04-02 00:31:18
【问题描述】:

如果标签发生变化,是否可以在 iPhone 上使用 VoiceOver 来宣布更新的文本?

这类似于 ARIA 中的实时区域。

谢谢。

【问题讨论】:

    标签: iphone wai-aria voiceover


    【解决方案1】:

    您可以让 VoiceOver 播报您喜欢的任何文字:

    UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, @"Your text");
    

    如果标签应在更新后立即公布其文本,只需扩展 UILabel 并覆盖 setText 方法。

    .h 文件:

    @interface UIVoicedLabel : UILabel {
    
    }
    
    @end
    

    及其实现:

    #import "UIVoicedLabel.h"
    
    @implementation UIVoicedLabel
    
    - (void) setText:(NSString *)text {
        // Set the text by calling the base class method.
        [super setText:text];
        // Announce the new text.
        UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, text);
    }
    
    @end
    

    这对我来说非常有效:)

    【讨论】:

      【解决方案2】:

      这是 Swift 4 版本

      UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: "Your text")
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多