UITextView - installing a font that does not work with iOS 6 on Xcode 5

I use storyboards for my user interface. I previously used Xcode 4.6 and was released on iOS 6. Since then, I updated iOS 7 with Xcode 5 and updated the storyboard to work well with Xcode 5. I have one problem:

UITextView does not want to display font changes inside the code. Text color changes work fine. Any other property changes are in order. Font, not at all. I used a custom font, so I checked different fonts of different sizes (i.e. systemFontOfSize: , but that didn't work. In the text view, only the font that is installed in the storyboard is displayed. What am I missing here? Are there any auto-layout limitations that fight such things? I had several limitations problems during the migration, but as I said, fonts work fine in iOS 7.

I assume that something in the storyboard is missing me, as if I create a UIViewController and add a text view to the code, it works fine.

I would add code, but I'm not sure if it helps at all in this case.

+64
ios objective-c xcode uistoryboard
01 Oct '13 at 10:19
source share
11 answers

The problem was caused by the fact that the editable property was false in the storyboard. I don’t know why this made the font remain unchanged - and only on iOS 6.

+55
01 Oct '13 at 11:04 on
source share

Even a stranger, this only happens on the iPhone, not on the iPad.

If you install the font in the code and do not want an editable text view, do the following:

 textView.editable = YES; textView.font = newFont; textView.editable = NO; 
+113
Oct 03 '13 at 20:27
source share

In my case, this is a matter of the “selectable” property of the UITextView.

So, I checked the "selectable" property in the UITextView in the storyboard editor to set it to YES To set selectable

and later in viewWillAppear set this property to NO.

 textview.text = @"some text"; textview.selectable = NO; 
+74
Dec 17 '13 at 6:38
source share

For me, this works if you set the text of your UITextView and after setting the font (the same for color):

 _myTextView.text = @"text"; [_myTextView setFont:[UIFont fontWithName:@"Helvetica Neue" size:18.0f]]; _myTextView.textColor = [UIColor whiteColor]; 
+19
03 Oct '13 at 20:35
source share

Thanks for answers. The problem is still present on iOS9. What I found out is that when you set " User Interaction Enabled = false " in Interface Builder, you can leave Editable and Selectable = true , and the user will not be able to edit the text view.

So my solution is:

  • Set User Interaction Enabled = False in IB
  • Set Editable = True to IB
  • Set Selectable = True to IB
  • Customize the text view in any way.
+14
Mar 10 '16 at
source share

Code for quick:

 textOutlet.editable = true textOutlet.textColor = UIColor.whiteColor() textOutlet.font = UIFont(name: "ArialMT", size: 20) textOutlet.editable = false 

Or, if you change the text first, it is magically solved

 textOutlet.text = "omg lol wtf" textOutlet.textColor = UIColor.whiteColor() textOutlet.font = UIFont(name: "ArialMT", size: 20) 
+10
Dec 07 '14 at 21:05
source share

I found that the font size is ignored. This was allowed by checking the box: Selectable (by selecting the UITextView in the storyboard)

+6
Sep 23 '15 at 19:37
source share

This problem only occurs when the Selectable property is set to FALSE in the interface builder.

If you need the Editable and Selectable properties to be set to FALSE, do it from CODE, not from Interface Builder.

To summarize, create editable and selectable properties = YES in the Interface Builder , and then add the following code if you need the FALSE properties:

 _textView.editable = NO; _textView.selectable = NO; 

Hope this helps,

+6
Jan 01 '15 at 19:08
source share

The Swift 3 model that worked for me:

 extension UITextView { func setFontAndUpdate(_ font: UIFont?) { self.font = font // Font doesn't update without text change let text = self.text self.text = nil self.text = text } } 
+1
May 03 '17 at 11:39 a.m.
source share

In my case (development on Xcode 7.3, iOS 9),

The reason was the installation order of the text and the font-family / size, and not the options for the editable or selectable set of answers. (and I don't get any xib storyboard in this Textview.)

If I enter as

 [myTextView setFont:[UIFont fontWithName:@"HelveticaNeue-Italic" size:20]]; myTextView.attributedText = mAttStr; 

that family and font size don't change, but otherwise when I undo these two steps, it works. The text setting should be ahead of the font family / size setting.

0
Apr 09 '16 at 7:51
source share

As mentioned by others:

 textView.font = UIFont.systemFont(ofSize: 16) textView.isEditable = false 

ps it is not necessary to set isEditable as true , since it is true by default: a little shorter, a little nicer

0
Mar 22 '17 at 17:25
source share



All Articles