Search code examples
ioslocalizationnsstringuitextviewnsattributedstring

Attributed UITextView doesn't work with Korean symbols


Attributed UITextView doesn't work with Korean symbols. Steps to reproduce:

  • Add UITextView to the form.
  • Use the following code:
NSDictionary *attributes = @{
    NSFontAttributeName:[UIFont fontWithName:@"HelveticaNeue" size:15], 
    NSForegroundColorAttributeName:[UIColor blackColor]};
[textView setAttributes:attributes
    range:NSMakeRange(0, textView.text.length)];
  • Run the application, type any text on Korean (에서 보냄) and tap or press Enter.

The Korean text will disappear or will be replaced by several trash symbols. Why? How can I fix it?

P.S. The is an interesting answer on the question UITextField text disappears on every other keystroke But I'm creating UITextView object on the code.


Solution

  • The following incorrect code works fine:

    NSDictionary *attributes = @{
        NSFontAttributeName:[/*UIFont fontWithName:@"HelveticaNeue" size:15],*/
        NSForegroundColorAttributeName:[UIColor blackColor]};
    [textView addAttributes:attributes
        range:NSMakeRange(0, textView.text.length)];