66

I'm using storyboards for my UI. I was previously using XCode 4.6 and released on iOS 6. I have since updated to iOS 7 using XCode 5 and updated the Storyboard to work nicely with XCode 5. I have one issue though:

UITextView doesn't want to display font changes within code. Text colour changes work fine. Any other property changes are fine. Font, not at all. I was using a custom font, so I checked different fonts with different sizes (i.e. systemFontOfSize:) but that didn't work. The text view only shows the font that's set in the Storyboard. What could I be missing here? Are there any auto-layout constraints that mess with this sort of thing? I had a few issues with constraints during the migration, but as I said, the fonts work fine in iOS 7.

I guess it's something in the Storyboard that I'm missing, as if I create a UIViewController and add a text view in code, it works fine.

I'd put up some code, but I'm not sure it'd help at all in this case.

1
  • 2
    This is the most bizarre bug in iOS, and it is still totally broken (mid 2016). Commented Jul 3, 2016 at 22:40

12 Answers 12

114

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

If you're setting the font in code and don't want an editable text view, do this:

textView.editable = YES;
textView.font = newFont;
textView.editable = NO;
Sign up to request clarification or add additional context in comments.

9 Comments

this is not specific to iphone, the fix works for ipad air running ios 7.0.6
Weird. The project where I discovered this, it affected iOS 6 iPhone but not iOS 6 iPad or iOS 7 anything. But it's good to verify that it's a general-purpose fix.
Works for textColor as well
Thanks, this trick works for me...I am using Xcode 6.2 and iOS 8.2.
Sadly still required in iOS9.
|
74

In my case, it is matter of 'selectable' property of UITextView.

So I checked 'selectable' property of UITextView in Storyboard Editor to set it YES To set selectable

and later in viewWillAppear set this property to NO.

textview.text = @"some text";
textview.selectable = NO;

3 Comments

This was actually my problem too. Makes no sense.
Same here - set text to white in Storyboard - nothing happens stays "default" until I set "selectable" - why?
Worked for me as well. Although in talking with a co-worker we're thinking that this might be because it's causing the UITextView to re-draw.
56

The issue was caused by the editable property being false in the Storyboard. I have absolutely no idea why this caused the font to remain unchanged - and only on iOS 6.

5 Comments

This didn't work for me, but setting the font after setting the text did. Go figure. Thanks Apple!
checking "Selectable" or "editable" worked for me too. This is definitely a bug on Apple's end.
This also applies to the text color in my case.
Problem and solution still apply in iOS 9 (Xcode 7.3)
Shame on you Apple! Just stolen my hours!
21

For me it's work if you set the text of your UITextView and after set the font (same for color) :

_myTextView.text = @"text";
[_myTextView setFont:[UIFont fontWithName:@"Helvetica Neue" size:18.0f]];
_myTextView.textColor = [UIColor whiteColor];

3 Comments

It's crazy that we have to experiment with random cocktails of code to get the most basic things like this working. This the only one that worked for me.
@dragonflyesque yes... It was for iOS 6. Do you test on iOS 9 and same result ?
This helped me fix my issue for iOS 8.
13

Thank you for all the answers guys. Issue is still present on iOS9. What i've found out, is that when you set "User Interaction Enabled = false" in the Interface Builder you can leave Editable and Selectable = true and user will not be able to edit a text view.

So, my solution is:

  1. Set User Interaction Enabled = False in IB
  2. Set Editable = True in IB
  3. Set Selectable = True in IB
  4. Configure your text view in whatever way you want.

Comments

11

Code for swift:

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 magically gets solved

textOutlet.text = "omg lol wtf"
textOutlet.textColor = UIColor.whiteColor()
textOutlet.font = UIFont(name: "ArialMT", size: 20)

Comments

7

I found the font size was being ignored. This was resolved by ticking the checkbox called: Selectable (having selected the UITextView within the storyboard)

Comments

5

This issue only happens when setting Selectable property to FALSE in the Interface Builder.

In case you are required to have the Editable and Selectable properties set to FALSE do it from the CODE and not in the Interface Builder.

Summing up, make Editable and Selectable properties = YES in the Interface Builder and then add the following code in case you need the properties to be FALSE:

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

Hope this helps,

Comments

1

Swift 3 category 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
    }
}

Comments

0

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

The cause was the order of setting text and font-family/size, not the options of editable or selectable many answers tell there.(and I don't get any storyboard, xib on that Textview.)

If I input like

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

then the font's family and size are not changed, but else when I reverse those two step, it works. Setting text should be ahead of setting font's family/size.

Comments

0

As mentioned by others:

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

p.s. no need to first set isEditable as true since it's true by default: a little shorter, a little nicer

Comments

0

In my case, I solved by setting the new font in "viewDidLayoutSubviews".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.