Skip to content

Instantly share code, notes, and snippets.

@tooszovski
Created August 11, 2017 13:02
Show Gist options
  • Save tooszovski/bff559a3056db1207864c490faea976d to your computer and use it in GitHub Desktop.
Save tooszovski/bff559a3056db1207864c490faea976d to your computer and use it in GitHub Desktop.
UITextView resizable by content with external height constraint
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