Attributed UITextView doesn't work with Korean symbols

空扰寡人 提交于 2020-01-06 07:34:47

问题


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.


回答1:


Use This code it will help you.

    //[_txtViewChallangeDescription setBackgroundColor:[UIColor redColor]];

     _txtViewChallangeDescription.font = [UIFont fontWithName:kFontHelvetica size:kFontSize14];
    [_txtViewChallangeDescription setTextColor:[UIColor blackColor]];
    [_txtViewChallangeDescription setEditable:NO];
    _txtViewChallangeDescription.delegate=self;

    _txtViewChallangeDescription.scrollEnabled=NO;
    _txtViewChallangeDescription.textContainer.lineFragmentPadding = 0;
    _txtViewChallangeDescription.textContainerInset = UIEdgeInsetsZero;
    NSDictionary *attrDict = @{
                               NSFontAttributeName : [UIFont fontWithName:kFontHelvetica size:kFontSize14],

                               NSForegroundColorAttributeName :[UIColor colorWithRed:152.0/255.0f green:132.0/255.0f blue:43.0/255.0f alpha:1.0f]
                               };
    [_txtViewChallangeDescription setLinkTextAttributes:attrDict];



回答2:


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)];


来源:https://stackoverflow.com/questions/24845623/attributed-uitextview-doesnt-work-with-korean-symbols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!