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

前端 未结 13 1901
伪装坚强ぢ
伪装坚强ぢ 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-28 03:46

    The answer given by bilobatum worked perfectly With auto layout, i.e subclassing the textview.

    If you want to limit the height of the text view add another constraint (I added it using storyboard i.e. height <= 166 (height as per your need))

    Then inside subclass reduce the priority of height constraint to 750 (self.heightConstraint.priority = 750) to avoid conflict between height constraint added in subclass and height constraint added on storyboard.

提交回复
热议问题