UITextView - setting font not working with iOS 6 on XCode 5
Solution 1
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.
Solution 2
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;
Solution 3
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
and later in viewWillAppear set this property to NO.
textview.text = @"some text";
textview.selectable = NO;
Solution 4
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];
Solution 5
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:
- Set User Interaction Enabled = False in IB
- Set Editable = True in IB
- Set Selectable = True in IB
- Configure your text view in whatever way you want.
Harry
Updated on July 05, 2022Comments
-
Harry almost 2 years
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.
-
ToddB over 10 yearsThis didn't work for me, but setting the font after setting the text did. Go figure. Thanks Apple!
-
Tom Kincaid over 10 yearsThis was actually my problem too. Makes no sense.
-
palaniraja about 10 yearsthis is not specific to iphone, the fix works for ipad air running ios 7.0.6
-
jab about 10 yearsWeird. 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.
-
Amrendra Pratap Singh about 10 yearsI am having the same problem for UILabel. Have you any idea how to overcome this ?
-
jab about 10 yearsI didn't see this for labels. I'd suspect you don't have your IBOutlet connected correctly. Is your label nil?
-
Dannie P about 10 yearsfiled bug to apple radar #16781060 for this
-
Cameron E over 9 yearschecking "Selectable" or "editable" worked for me too. This is definitely a bug on Apple's end.
-
Steve O'Connor over 9 yearsSame here - set text to white in Storyboard - nothing happens stays "default" until I set "selectable" - why?
-
rharvey over 9 yearsWorks for textColor as well
-
Kent Robin over 9 yearsThis also applies to the text color in my case.
-
Admin about 9 yearsWorked 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.
-
Kirti Nikam about 9 yearsThanks, this trick works for me...I am using Xcode 6.2 and iOS 8.2.
-
tounaobun over 8 yearsSadly still required in iOS9.
-
dragonflyesque over 8 yearsIt'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.
-
Jordan Montel over 8 years@dragonflyesque yes... It was for iOS 6. Do you test on iOS 9 and same result ?
-
dragonflyesque over 8 yearsThis helped me fix my issue for iOS 8.
-
NSPratik about 8 yearsI stuck in this issue many times and everytime, I came to this answer :D, Thanks a lot @jab
-
marco almost 8 yearsProblem and solution still apply in iOS 9 (Xcode 7.3)
-
Murat Yasar over 7 yearsShame on you Apple! Just stolen my hours!