I need to use two different fonts in a text view, so I set the Text attribute to textViewDidChange. But for the Japanese keyboard, the input character is re-entered.
It works for english keyboard. It also works for the Japanese keyboard when you use plain text instead of the Text attribute.
My code is:
- (void)viewDidLoad { [super viewDidLoad]; UITextView *textView = [[UITextView alloc] initWithFrame:self.view.frame]; textView.delegate = self; [self.view addSubview:textView]; } - (void)textViewDidChange:(UITextView *)textView { NSLog(@"TOTAL: %@", textView.text); textView.attributedText = [[NSMutableAttributedString alloc] initWithString: textView.text]; } - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { NSLog(@"ADDED: %@", text); return YES; }
Output:
2015-07-15 13:51:10.156 japKeyTest[32163:5765000] ADDED: a 2015-07-15 13:51:10.167 japKeyTest[32163:5765000] TOTAL: γ2015-07-15 13:51:11.376 japKeyTest[32163:5765000] ADDED: a 2015-07-15 13:51:11.378 japKeyTest[32163:5765000] TOTAL: γγγ2015-07-15 13:51:12.054 japKeyTest[32163:5765000] ADDED: a 2015-07-15 13:51:12.055 japKeyTest[32163:5765000] TOTAL: γγγγγγ
Expected:
2015-07-15 13:51:10.156 japKeyTest[32163:5765000] ADDED: a 2015-07-15 13:51:10.167 japKeyTest[32163:5765000] TOTAL: γ2015-07-15 13:51:11.376 japKeyTest[32163:5765000] ADDED: a 2015-07-15 13:51:11.378 japKeyTest[32163:5765000] TOTAL: γγ2015-07-15 13:51:12.054 japKeyTest[32163:5765000] ADDED: a 2015-07-15 13:51:12.055 japKeyTest[32163:5765000] TOTAL: γγγ
Any idea how to enter attribute text with a Japanese keyboard and get a normal result? (no extra characters)
ios objective-c uitextview keyboard
Jakub vodak
source share