简体   繁体   中英

Accessibility feature for special characters iOS

I am new to accessibility feature. The problem in my application is that some special characters(. -) are not spoken by the application correctly for example

-0.7 is spelt as 7

You could use a number formatter and the "spell out" style to create a more suitable accessibilityLabel for those strings. VoiceOver will then read this string for that label but it's not visible in the UI somewhere.

NSNumber *number = @(-0.7);
NSNumberFormatter *formatter = [NSNumberFormatter new];
formatter.numberStyle = NSNumberFormatterSpellOutStyle;
formatter.locale = [NSLocale currentLocale];

NSString *spelledOutNumber = [formatter stringFromNumber:number];

// set that as the accessibility label to be read instead of the number
yourLabel.accessibilityLabel = spelledOutNumber; 

That would also give you a solution that works well with different locales (some sample output below):

en_US -> minus zero point seven
de_DE -> minus null Komma sieben
fr_FR -> moins zéro virgule sept
ja_JP -> マイナス〇・七
es_ES -> menos cero coma siete
ru_RU -> минус ноль запятая семь
sv_SE -> minus noll komma sju

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM