How do I size a UITextView to its content on iOS 7?

前端 未结 13 1898
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 03:04

I\'ve been using the accepted answer here for years.

On iOS 7, the contentSize.height becomes the frame.height-8, regardless of text content.

What\'s a worki

13条回答
  •  被撕碎了的回忆
    2020-11-28 03:53

    I wrote a category over UITextView:

    - (CGSize)intrinsicContentSize {
        return self.contentSize;
    }
    
    - (void)setContentSize:(CGSize)contentSize {
        [super setContentSize:contentSize];
        [self invalidateIntrinsicContentSize];
    }
    

    When UIKit sets its contentSize, UITextView adjusts its intrinsic content size. That plays nicely with autolayout.

提交回复
热议问题