2013-07-19 78 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

相關問題