Created
August 11, 2017 13:02
-
-
Save tooszovski/bff559a3056db1207864c490faea976d to your computer and use it in GitHub Desktop.
UITextView resizable by content with external height constraint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension UITextView { | |
open override func invalidateIntrinsicContentSize() { | |
// UITextView intrinsicContentSize only exists if scrolling is disabled | |
self.isScrollEnabled = false | |
super.invalidateIntrinsicContentSize() | |
} | |
open override func layoutSubviews() { | |
super.layoutSubviews() | |
let contentSize = self.sizeThatFits(self.bounds.size) | |
if contentSize.height > self.frame.height { | |
self.isScrollEnabled = true | |
return | |
} | |
self.isScrollEnabled = false | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment