iPhone - make VoiceOver announce label text change

泪湿孤枕 提交于 2019-12-13 12:01:20

问题


Is it possible using VoiceOver on the iPhone to announce the updated text on a label if it changes?

This would be analogous to a live-region in ARIA.

Thanks.


回答1:


You can make VoiceOver announce any text you like with:

UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, @"Your text");

If a label should announce its text as soon as it is updated, simply extend the UILabel and override the setText method.

The .h File:

@interface UIVoicedLabel : UILabel {

}

@end

And its implementation:

#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

This worked perfectly for me :)




回答2:


Here is the Swift 4 version

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


来源:https://stackoverflow.com/questions/5520238/iphone-make-voiceover-announce-label-text-change

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