Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITextView drawing improperly on iOS 7

This code:

UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, width, 80.0f)];
[textView setText:@"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."];
[textView setEditable:NO];
[self addSubview:textView];
[textView setScrollEnabled:NO];
[textView setText:[textView.text stringByAppendingFormat:@"\nHello!"]];
[textView setScrollEnabled:YES];

Will cause the UITextView to draw improperly at the bottom. It seems that iOS 7 does not increase the contentSize when scrollEnabled is false. This code would work fine in iOS 6, though. Is there something that I can do to fix this? I need scroll disabled, otherwise it will scroll back to the top when the text is added, which is not what I want.

like image 933
RileyE Avatar asked Sep 19 '13 19:09

RileyE


1 Answers

Ran into the same problem. Here's an ugly temporary hack FWIW:

NSAttributedString* text = textView.attributedText;
_textView.text = @"";
_textView.attributedText = text;

This seems to force the resizing and redraw.

like image 131
Chen Lim Avatar answered Nov 18 '22 16:11

Chen Lim