UITextView style is being reset after setting text property UITextView style is being reset after setting text property ios ios

UITextView style is being reset after setting text property


Sitting with this for hours, I found the bug.If the property "Selectable" = NO it will reset the font and fontcolor when setText is used.

So turn Selectable ON and the bug is gone.


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

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

implementation

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


If you want your text view to be "read only" you can check Editable and Selectable and uncheck User Interaction Enabled, with this the UITextView was behaving as I wanted

enter image description here

enter image description here