【发布时间】:2011-04-02 00:31:18
【问题描述】:
如果标签发生变化,是否可以在 iPhone 上使用 VoiceOver 来宣布更新的文本?
这类似于 ARIA 中的实时区域。
谢谢。
【问题讨论】:
如果标签发生变化,是否可以在 iPhone 上使用 VoiceOver 来宣布更新的文本?
这类似于 ARIA 中的实时区域。
谢谢。
【问题讨论】:
您可以让 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
这对我来说非常有效:)
【讨论】:
这是 Swift 4 版本
UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: "Your text")
【讨论】: