开发者

iPhone - make VoiceOver announce label text change

开发者 https://www.devze.com 2023-02-22 01:47 出处:网络
Is it possible using VoiceOver on the iPhone to announce the updated text on a label if it changes? This would be analog开发者_JS百科ous to a live-region in ARIA.

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

This would be analog开发者_JS百科ous to a live-region in ARIA.

Thanks.


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 :)


Here is the Swift 4 version

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

精彩评论

暂无评论...
验证码 换一张
取 消