Reputation: 1960
I have a text in either of below formats:
.03 hours
0.03 - 0.05 hours
In above cases accessibility should read in below format:
dot zero three hours
zero dot zero three (character name) zero dot zero five hours
But in real scenario it is reading like below:
three hours
zero dot zero three zero dot five hours
Like i mentioned above the number format is getting from json response as string type and it might be in any format like 0.03 hours, .03 hours, .03 - .05 hours, 4 - 5 hours
to fix the issue, I have tried many solutions like below but no luck
hoursLabel.accessibilityAttributedLabel = NSAttributedString(string: hoursLabel.text ?? "", attributes: [NSAttributedString.Key.accessibilitySpeechPunctuation: NSNumber(value: true)])
Can any one help me out, how to fix this scenario.
In may case it should work in all other units like .03 (unit)
Upvotes: 0
Views: 1122
Reputation: 5671
the number format is getting from json response as string type and it might be in any format like 0.03 hours, .03 hours, .03 - .05 hours, 4 - 5 hours
First of all, you should rearrange the incoming data so as to have the same defined format. Then, you just have to set up this format to be read out as desired by VoiceOver.
Hereunder, an ObjC code snippet from this complete 'date, time and numbers' explanation:
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel * hourLabel;
@end
@implementation ViewController
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"0.HH"];
NSDate * date = [dateFormatter dateFromString:@"0.05"];
_hourLabel.text = [NSDateFormatter localizedStringFromDate:date
dateStyle:NSDateFormatterNoStyle
timeStyle:NSDateFormatterShortStyle];
NSDateComponents * hourComponents = [[NSCalendar currentCalendar] components:NSCalendarUnitHour
fromDate:date];
_hourLabel.accessibilityLabel = [NSDateComponentsFormatter localizedStringFromDateComponents:hourComponents
unitsStyle:NSDateComponentsFormatterUnitsStyleSpellOut];
}
@end
Unless I misunderstood your need, you should reach your purpose using this rationale.
Upvotes: 2