问题
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