AccessibilityLabel无法按预期工作

时间:2014-11-17 10:26:57

标签: ios objective-c uilabel accessibility

我想在我的应用中支持VoiceOver,但我有一些问题。我有UITableView一些单元格,以支持VoiceOver我执行以下操作:

cell.labelMorning.accessibilityTraits = UIAccessibilityTraitStaticText;
cell.labelAfternoon.accessibilityTraits = UIAccessibilityTraitStaticText;

//Without VoiceOver
cell.labelMorning.text = [NSString stringWithFormat:@"%@ - %@", model.startTimeM, model.endTimeM];
cell.labelAfternoon.text = [NSString stringWithFormat:@"%@ - %@", model.startTimeA, model.endTimeA];

//When VoiceOver is activated
cell.labelMorning.accessibilityLabel = [NSString stringWithFormat:@ %@  to %@ a Clock ",model.startTimeM,model.endTimeM];
cell.labelAfternoon.accessibilityLabel = [NSString stringWithFormat:@" %@ to %@ a Clock",model.startTimeA,model.endTimeA];

但是当我激活VoiceOver时,每个Label都会被读取两次,这是错误的吗?

2 个答案:

答案 0 :(得分:0)

好的诀窍不是使用accessibilityLabel而是使用accessibilityValue !!

答案 1 :(得分:0)

为什么在设置标签文本后立即设置辅助功能标签?

您已经设置了accessibilityTrait,因此VoiceOver知道只读取该标签的文本。所以通过设置文本:

cell.labelMorning.text = [NSString stringWithFormat:@"%@ - %@", model.startTimeM, model.endTimeM];

您已经设置了accessibilityLabel了。我不确定这是否是您的源代码,但您可能希望向check if VoiceOver is running添加if语句,然后使文本包含'to'而不是' - '(如果是)。