Reputation: 1220
How to change the text color of particular word of textview text in ios5.I have implemented an app in that I displayed the mangalAshtak shlok in textview .It also has play button which plays audio file of mangal ashtak.Now I want to synchronise audio file with textview .I I have implemented this using NSMutableAttributedString in ios 6 as below
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]];
}
using above code it changed the color of text with audio file .In play button action I checked the current timing of AVAudioPlayer object & changed the respective text .But in ios 5 it doesn't work?
Upvotes: 1
Views: 887
Reputation: 45598
Support for attributed strings in UIKit classes like UITextView
was only added in iOS 6. To do this on earlier systems you will have to draw the strings yourself using Core Text or a framework like DTCoreText.
Upvotes: 2