Problems with contentSize property of UITextView in iOS7

In iOS6, you can check the contentSize property of UITextView right after you set the text. In iOS7, this will no longer work. 

- (void)setText:(NSString *)text
[_textView setText:text];

if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
CGSize size = CGSizeMake(_textView.textContainer.size.width, 0); CGRect rect = [text boundingRectWithSize:size
:@{NSFontAttributeName: _textView.font} context:nil];
UIEdgeInsets inset = _textView.textContainerInset; _textView.contentSize = CGSizeMake(ceil(rect.size.width) + inset.left + inset.right, ceil(rect.size.height) + + inset.bottom);

Leave a Comment