いくつかの属性を適用するために、レンダリングする前に、入力されたテキストをキャプチャする必要があります。
そのために、NSAttributedString と共に UITextView のデリゲート メソッド shouldChangeTextInRange を使用しています。これまでのところ、うまく機能しています。
問題は、UITextView が一定量のテキストを取得してスクロールを開始したときに、attributedText を変更すると一番上までスクロールし、次の char を使用すると最後までスクロールすることです。
タイピングしている間、そのダンスが上下に動き続けます..
属性付きテキストの代わりに textview.text を設定すると、動作します n
なにか提案を?
前もって感謝します。
- (BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
NSAttributedString * newString = [[NSAttributedString alloc] initWithString:text attributes:nil];
NSMutableAttributedString * string = [[NSMutableAttributedString alloc] initWithAttributedString:_textView.attributedText];
[string insertAttributedString:newString atIndex:range.location];
textView.attributedText = string;
range.location += text.length;
textView.selectedRange = range;
return NO;
}