Commit 9fae5e1f by Orkhan Alikhanov Committed by OrkhanAlikhanov

Added preferredMaxLayoutHeight to TextView

parent 9cd30b33
...@@ -263,6 +263,12 @@ open class TextView: UITextView { ...@@ -263,6 +263,12 @@ open class TextView: UITextView {
layoutShape() layoutShape()
layoutShadowPath() layoutShadowPath()
layoutPlaceholderLabel() layoutPlaceholderLabel()
guard isGrowEnabled else {
return
}
invalidateIntrinsicContentSize()
} }
/** /**
...@@ -284,6 +290,31 @@ open class TextView: UITextView { ...@@ -284,6 +290,31 @@ open class TextView: UITextView {
preparePlaceholderLabel() preparePlaceholderLabel()
} }
/// Maximum preffered layout height before scrolling.
open var preferredMaxLayoutHeight: CGFloat = 0 {
didSet {
invalidateIntrinsicContentSize()
}
}
/// A property indicating if textView allowed to grow.
private var isGrowEnabled: Bool {
return preferredMaxLayoutHeight > 0 && isScrollEnabled
}
open override var intrinsicContentSize: CGSize {
guard isGrowEnabled else {
return super.intrinsicContentSize
}
let insets = textContainerInsets
let w = bounds.width - insets.left - insets.right - 2 * textContainer.lineFragmentPadding
let placeholderH = placeholderLabel.sizeThatFits(CGSize(width: w, height: .greatestFiniteMagnitude)).height
let h = max(contentSize.height, placeholderH + insets.top + insets.bottom)
return CGSize(width: UIView.noIntrinsicMetric, height: min(h, preferredMaxLayoutHeight))
}
open override func insertText(_ text: String) { open override func insertText(_ text: String) {
fixTypingFont() fixTypingFont()
super.insertText(text) super.insertText(text)
......
...@@ -129,6 +129,7 @@ open class Toolbar: Bar { ...@@ -129,6 +129,7 @@ open class Toolbar: Bar {
prepareDetailLabel() prepareDetailLabel()
} }
/// A reference to titleLabel.textAlignment observation.
private var titleLabelTextAlignmentObserver: NSKeyValueObservation! private var titleLabelTextAlignmentObserver: NSKeyValueObservation!
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment