我有以下任何一种格式的文本:
.03 hours
0.03-0.05小时
在上述情况下,无障碍应以以下格式阅读:
点零三小时
零点零3(字符名)零点零5小时
但在实际情况下,如下所示:
三小时
零点零三零点5小时
正如我前面提到的,数字格式是从json响应中获得的字符串类型,它可以是任何格式,比如0.03小时、.03小时、.03 - .05小时、4-5小时。
为了解决这个问题,我尝试了很多解决方案,比如下面的方法,但是没有运气。
hoursLabel.accessibilityAttributedLabel = NSAttributedString(string: hoursLabel.text ?? "", attributes: [NSAttributedString.Key.accessibilitySpeechPunctuation: NSNumber(value: true)])有人能帮我解决这个问题吗?
在可能的情况下,它应该工作在所有其他单位,如.03 (单位)
发布于 2019-07-30 12:11:58
数字格式是从json响应中获得的字符串类型,它可以是任何格式,如0.03小时、.03小时、.03 - .05小时、4-5小时。
首先,您应该重新排列传入的数据,以便具有相同的定义格式。然后,您只需设置这个格式就可以按照VoiceOver的要求读出。
下面是来自这个ObjC的完成“日期、时间和号码”的解释代码片段
@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除非我误解了你的需要,否则你应该利用这个理由来达到你的目的。
https://stackoverflow.com/questions/57267541
复制相似问题