UITextView - some fonts cause text to disappear

I had an interesting problem with UITextView . I use this code to place a text view on the screen in the loadView controller:

 self.textView = [[UITextView alloc] init]; if (self.tutorialPage.text.length > 0) { self.textView.backgroundColor = [UIColor clearColor]; self.textView.editable = NO; self.textView.text = self.tutorialPage.text; self.textView.showsVerticalScrollIndicator = NO; self.textView.textColor = [UIColor whiteColor]; self.textView.textAlignment = NSTextAlignmentLeft; self.textView.translatesAutoresizingMaskIntoConstraints = NO; //Later constraints are added } UIFont *font = [UIFont fontWithName:@"Noteworthy-Bold" size:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 20.0 : 15.0)]; self.textView.font = font; [self.view addSubview:self.textView]; 

Each line of this code causes, by the way, a textual representation, of course, on the screen. But for some reason, when the same code is called again to create another controller of the same type, the text is not displayed. However, when I select text in text form by pressing and holding, the text suddenly appears.

Even weirder when I change this line

 UIFont *font = [UIFont fontWithName:@"Noteworthy-Bold" size:(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 20.0 : 15.0)]; 

to use a different font name, for example @"Noteworthy-Light" or @"TimesNewRomanPS-BoldMT" , the text view behaves as expected ... What could be causing this problem?

Has anyone ever seen this problem before? If yes, please share how you solved it or worked.

+4
source share
2 answers

I had a similar problem. I solved this by first setting UIFont and then setting UIColour + NSTextAlignment. In short, you should set: font → colors / other attributes.

0
source

If you want to make this text field the first responder, than make it in viewDidAppear instead of viewWillAppear. Your problem will be resolved.

0
source

Source: https://habr.com/ru/post/1492213/


All Articles