ios - Replace part of UITextView's attributed text -


i'm trying create text view in app. highlights syntax , displays highlighted text in uitextview via attributedtext. here's code:

nsmutablestring *ms = [[nsmutablestring alloc] initwithstring:self.text]; [ms replacecharactersinrange:range withstring:text]; self.attributedtext = [syntaxhighlighter highlight:ms inrange:[self visiblerangeoftext]]; [self setselectedrange:nsmakerange(range.location + text.length, 0)]; 

the problem large texts, has replace whole text in 3rd line. there way replace part of text without replacing whole content?

uitextview implements uitextinput protocol.

if want replace part of text without replacing whole content, can use method:

- (void)replacerange:(uitextrange *)range withtext:(nsstring *)text; 

but in special case (when calling other class), method not effective. dont know why used:

double delayinseconds = 0.2; dispatch_time_t poptime = dispatch_time(dispatch_time_now, (int64_t)(delayinseconds * nsec_per_sec)); dispatch_after(poptime, dispatch_get_main_queue(), ^(void){      //call method change text of textview here... }); 

good luck!


Comments