2013-07-19 76 views
1

如何更改ios5.I中textview文本的特定单词的文本颜色已经实现了一个应用程序,我在textview中显示了mangalAshtak shlok。它还具有播放按钮起着曼加勒ashtak.Now的音频文件,我想与同步TextView的。②音频文件都使用上面的代码在iOS 6中实现了这个使用NSMutableAttributedString如下如何更改ios5中textview的特定单词的文本颜色

if(seconds>=42 && seconds<43) 
    { 
    NSMutableAttributedString * string = [[NSMutableAttributedString alloc]initWithString:self.textView.text]; 
    NSString *word= [shlok2 objectAtIndex:0]; //array shlok 2 contains each word of shlok  
    NSLog(@"%@",word); 
    NSRange range=[self.textView.text rangeOfString:word]; 
    [string addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:range]; 
    [self.textView setAttributedText:string]; 
    [textView setFont:[UIFont systemFontOfSize:16]]; 
} 

它改变文本的颜色搭配音频文件。在播放按钮动作中,我检查了当前AVAudioPlayer对象&的时间改变了各自的文本。但是在ios 5中它不起作用?

回答

2

仅支持UIKit类(如UITextView)中的属性字符串仅在iOS 6中添加。要在早期系统上执行此操作,您必须使用核心文本或像DTCoreText这样的框架自行绘制字符串。

+0

我已经从GitHub下载了DTCoreText框架并试图运行,但我得到了像'DTUtils.h'文件没有找到的错误。请帮助如何在我的项目中使用该框架 – poojathorat

相关问题