UITextView style is being reset after setting text property


I ran into the same issue (on Xcode 6.1) and while John Cogan's answer worked for me, I found that extending the UITextView class with a category was a better solution for my particular project.


@interface UITextView (XcodeSetTextFormattingBugWorkaround)
    - (void)setSafeText:(NSString *)textValue;


@implementation UITextView (XcodeSetTextFormattingBugWorkaround)
- (void)setSafeText:(NSString *)textValue
    BOOL selectable = [self isSelectable];
    [self setSelectable:YES];
    [self setText:textValue];
    [self setSelectable:selectable];


I have UITextView *_masterText and after call method setText property font is being reset. It's happening after I change sdk 7. _masterText is IBOutlet, global and properties are set in storyboard. It's only me or this is general SDK bug?

@interface myViewController : UIViewController
  IBOutlet UITextView *_masterText;

@implementation myViewController

    [_masterText setText:@"New text"];

Changing Font in UITextView does not work in iOS7

I have a strange behavior in iOS 7. Font is smaller than I expect, if I was set it in to the xib.

If I set font after setting the text it's works for me. Otherwise font is smaller.

Try this:

  cell.newsItemDescription.text = newsDescriptions[indexPath.row];
  cell.newsItemDescription.font = [UIFont fontWithName:@"didot" size:20];

I ran into a weird bug (Xcode 7.2.1), where unchecking "Selectable" in IB was causing the UITextView to not adhere to the font settings specified through IB.

I had similar problem with Raleway font. I was using Raleway-Bold.ttf (PostScript name: Raleway-Bold) and Raleway-Regular.ttf (PostScript name: Raleway) in my app. When two of those fonts were added to the project I was unable to draw Raleway-Bold in UITextView (either by setting font programmatically or in IB with FontReplacer). I was ending up with Raleway-Regular in UITextView, no problem with UILabel. When I have deleted Raleway-Regular there was no problem in both text view and label.

What I needed to do to draw Raleway-Bold on UITextView, but not resign from Regular, was to change PostScript name of Raleway-Regular, which was just Raleway to some other name. In my case it was Raleway-Reg. It was a fix :)

UITextView changing the source text

To change the text of a UITextView, set its text property:

textView.text = @"your text here";

You can call this from within a button's selector like so:

UIButton *yourButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[yourButton setTitle:@"click to change textview's text" forState:UIControlStateNormal];
[yourButton addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];


- (void)buttonClicked:(id)sender {

    textView.text = @"your text";