Commit 84e574ef by Orkhan Alikhanov

Added minimumTextHeight and adjusted TextView placeholder layout

parent 211e4b48
......@@ -223,6 +223,7 @@ private extension Editor {
let rightPadding = inset.right + textView.textContainer.lineFragmentPadding
let w = bounds.width - leftPadding - rightPadding
var h = placeholderLabel.sizeThatFits(CGSize(width: w, height: .greatestFiniteMagnitude)).height
h = max(h, textView.minimumTextHeight)
h = min(h, bounds.height - inset.top - inset.bottom)
placeholderLabel.bounds.size = CGSize(width: w, height: h)
......
......@@ -65,8 +65,8 @@ public protocol TextFieldDelegate: UITextFieldDelegate {
open class TextField: UITextField {
/// Minimum TextField height
private var minimumTextHeight: CGFloat = 32
/// Minimum TextField text height.
private let minimumTextHeight: CGFloat = 32
/// Default size when using AutoLayout.
open override var intrinsicContentSize: CGSize {
......
......@@ -302,6 +302,9 @@ open class TextView: UITextView {
return preferredMaxLayoutHeight > 0 && isScrollEnabled
}
/// Minimum TextView text height.
internal let minimumTextHeight: CGFloat = 32
open override var intrinsicContentSize: CGSize {
guard isGrowEnabled else {
return super.intrinsicContentSize
......@@ -311,7 +314,8 @@ open class TextView: UITextView {
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)
var h = max(minimumTextHeight, placeholderH) + insets.top + insets.bottom
h = max(h, contentSize.height)
return CGSize(width: UIView.noIntrinsicMetric, height: min(h, preferredMaxLayoutHeight))
}
......@@ -384,15 +388,15 @@ fileprivate extension TextView {
return
}
placeholderLabel.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2
let x = textContainerInset.left + textContainer.lineFragmentPadding
let y = textContainerInset.top
placeholderLabel.sizeToFit()
placeholderLabel.frame.origin.x = x
placeholderLabel.frame.origin.y = y
placeholderLabel.frame.size.width = textContainer.size.width - textContainerInset.right - textContainer.lineFragmentPadding
let insets = textContainerInsets
let leftPadding = insets.left + textContainer.lineFragmentPadding
let rightPadding = insets.right + textContainer.lineFragmentPadding
let w = bounds.width - leftPadding - rightPadding
var h = placeholderLabel.sizeThatFits(CGSize(width: w, height: .greatestFiniteMagnitude)).height
h = max(h, minimumTextHeight)
h = min(h, bounds.height - insets.top - insets.bottom)
placeholderLabel.frame = CGRect(x: leftPadding, y: insets.top, width: w, height: h)
}
}
......
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