UITextView assignedText destacado e destaque de sintaxe
Portanto, com o iOS 6, um UITextView pode receber um assignedString, que pode ser útil para realçar a sintaxe.
Eu estou fazendo alguns padrões de regex em-textView:shouldChangeTextInRange:replacementText:
e muitas vezes eu preciso mudar a cor de uma palavra já digitada. Não vejo outras opções além de redefinir o assignedText, o que leva tempo.
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
//A context will allow us to not call -attributedText on the textView, which is slow.
//Keep context up to date
[self.context replaceCharactersInRange:range withAttributedString:[[NSAttributedString alloc] initWithString:text attributes:self.textView.typingAttributes]];
// […]
self.textView.scrollEnabled = FALSE;
[self.context setAttributes:self.defaultStyle range:NSMakeRange(0, self.context.length)];
[self refresh]; //Runs regex-patterns in the context
textView.attributedText = self.context;
self.textView.selectedRange = NSMakeRange(range.location + text.length, 0);
self.textView.scrollEnabled = TRUE;
return FALSE;
}
Isso funciona ok no simulador, mas em um iPad 3 cada-setAttributedText
leva algumas centenas de milissegundos.
Eu arquivei um bug para a Apple, com o pedido de ser capaz de alterar o attributeText. Ele foi marcado como duplicado, então não consigo ver o que estão dizendo sobre isso.
A questãoA questão mais específica: Como posso alterar a cor de determinados intervalos em um UITextView, com um texto grande e multicolorido, com desempenho suficiente para fazer isso em todos osshouldReplaceText...
?
A questão mais ampla: Como você faz o realce de sintaxe com um UITextView no iOS 6?