Commit b5faaef4 by Orkhan Alikhanov Committed by OrkhanAlikhanov

Added option to disable operations on textview's placeholderLabel

parent f47aaf8d
...@@ -134,6 +134,9 @@ open class TextView: UITextView { ...@@ -134,6 +134,9 @@ open class TextView: UITextView {
@IBInspectable @IBInspectable
public let placeholderLabel = UILabel() public let placeholderLabel = UILabel()
/// A property to enable/disable operations on the placeholderLabel
internal var isPlaceholderLabelEnabled: Bool = true
/// Placeholder normal text /// Placeholder normal text
@IBInspectable @IBInspectable
open var placeholderColor = Color.darkText.others { open var placeholderColor = Color.darkText.others {
...@@ -325,12 +328,20 @@ fileprivate extension TextView { ...@@ -325,12 +328,20 @@ fileprivate extension TextView {
fileprivate extension TextView { fileprivate extension TextView {
/// Updates the placeholderLabel text color. /// Updates the placeholderLabel text color.
func updatePlaceholderLabelColor() { func updatePlaceholderLabelColor() {
guard isPlaceholderLabelEnabled else {
return
}
tintColor = placeholderColor tintColor = placeholderColor
placeholderLabel.textColor = placeholderColor placeholderLabel.textColor = placeholderColor
} }
/// Updates the placeholderLabel visibility. /// Updates the placeholderLabel visibility.
func updatePlaceholderVisibility() { func updatePlaceholderVisibility() {
guard isPlaceholderLabelEnabled else {
return
}
placeholderLabel.isHidden = !isEmpty placeholderLabel.isHidden = !isEmpty
} }
} }
...@@ -338,6 +349,10 @@ fileprivate extension TextView { ...@@ -338,6 +349,10 @@ fileprivate extension TextView {
fileprivate extension TextView { fileprivate extension TextView {
/// Laysout the placeholder UILabel. /// Laysout the placeholder UILabel.
func layoutPlaceholderLabel() { func layoutPlaceholderLabel() {
guard isPlaceholderLabelEnabled else {
return
}
placeholderLabel.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2 placeholderLabel.preferredMaxLayoutWidth = textContainer.size.width - textContainer.lineFragmentPadding * 2
let x = textContainerInset.left + textContainer.lineFragmentPadding let x = textContainerInset.left + textContainer.lineFragmentPadding
......
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