【发布时间】:2015-01-19 13:22:39
【问题描述】:
我需要在不刷新页面的情况下在播放 TTS 时动态更新 UiTextView 内容中的单词。
问题:当 tts 播放每个单词时,delegate(willSpeakRangeOfSpeechString:(NSRange)characterRange utterance:(AVSpeechUtterance *)utterance) 正在调用。
所以当时我正在使用NSMutableAttributedString更新文本颜色。
在这个过程中,textview中的内容是不稳定的,因为每个word页面都在刷新。
所以我需要在不刷新页面的情况下更新 textview 中的文本。
我是这样写代码的。
NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:_theContent ];
[attrStr addAttribute:NSFontAttributeName 值:[UIFont systemFontOfSize:self.fontSize] range:[self wholeArticleRange]];
[attrStr addAttribute:NSForegroundColorAttributeName 值:[UIColor redColor] range:theRange];
textview.attributedText = attrStr;
--在android中我们使用spannable class来做到这一点。 IOS有这样的类吗?
请尽快给我们解决方案
提前致谢。
【问题讨论】:
标签: ios objective-c uitextview text-to-speech