Question

My app uses a UITextView to input Syriac text (Estrangelo font), but UITextView renders some letters incorrectly like this:

enter image description here

I tested it with a UILabel and a UITextView. UILabel displays it correctly, but UITextView incorrectly displays the top dots and moves them to the bottom (see the above result).

This problem only occurs in iOS 7 and does not occur in iOS 6. Please tell me if there's any way to fix the problem.

This is my test code

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
label.center = CGPointMake(self.view.center.x, self.view.center.y-40);
label.font = [UIFont fontWithName:@"East Syriac Adiabene" size:24];
label.text = @"ܩ̈ ܡ̄ ܬ̇ ܒ̃";
[self.view addSubview:label];

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
textView.center = CGPointMake(self.view.center.x, self.view.center.y+40);
textView.font = [UIFont fontWithName:@"East Syriac Adiabene" size:24];
textView.text = @"ܩ̈ ܡ̄ ܬ̇ ܒ̃";
[self.view addSubview:textView];
Was it helpful?

Solution

I debugged this issue a little, and it seems to be a bug in the way NSLayoutManager layouts the text. As other answers pointed out, UITextView is build around TextKit since iOS7, and thus uses NSLayoutManager internally to layout text. UILabel uses Core Text to layout text directly. Both eventually use Core Text to render the glyphs.

You should open a bug report with Apple and post the number so people can duplicate it. The issue has not been fixed so far in iOS7.1 betas.

As a workaround, you can replace UITextView with other Core Text alternative editors, which layout and render directly with Core Text, where the issue does not exist.

I tested SECoreTextView, and it shows the text correctly. It implements a similar API to UITextView but internally uses Core Text.

Here is how it looks after swapping UITextView with SECoreTextView:

SETextView *textView = [[SETextView alloc] initWithFrame:CGRectMake(0, 0, 100, 40)];
textView.center = CGPointMake(self.view.center.x, self.view.center.y+40);
textView.font = [UIFont fontWithDescriptor:desc size:24];
textView.text = @"ܩ̈ ܡ̄ ܬ̇ ܒ̃";
textView.textColor = [UIColor blackColor];
textView.backgroundColor = [UIColor whiteColor];
textView.editable = YES;

[self.view addSubview:textView];

Using Core Text, the layout issue does not exist.

OTHER TIPS

Some days ago, I had the same problem as yours in iOS 7 (but the font was different). I set the FONT after setting the TEXT and it worked for me. So for your case:

textView.text = @"ܩ̈ ܡ̄ ܬ̇ ܒ̃"; // Setting the text.
textView.font = [UIFont fontWithName:@"East Syriac Adiabene" size:24]; // Setting the font and it's size.

It may seem silly, but it worked for me.

Also see this question/answer. There are many tips for using custom fonts with UITextView, which may be helpful for you.

EDIT :

iOS 7 also introduced a new selectable property on the UITextView for enabling text selection. So make sure you have done the following:

self.textField.editable = YES;
self.textField.selectable = ON;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top