Skip to content

Commit 950e525

Browse files
OlegOleg
authored andcommitted
Fix text and placeholder overlapping.
1 parent fb8ed8d commit 950e525

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Sources/TweePlaceholderTextField.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ public class TweePlaceholderTextField: UITextField {
5555
/// Custom placeholder label. You can use it to style placeholder text.
5656
public private(set) lazy var placeholderLabel = UILabel()
5757

58+
public override var text: String? {
59+
didSet {
60+
if let text = text, text.isEmpty == false {
61+
minimizePlaceholder()
62+
}
63+
}
64+
}
65+
66+
public override var attributedText: NSAttributedString? {
67+
didSet {
68+
if let attrText = attributedText, attrText.string.isEmpty == false {
69+
minimizePlaceholder()
70+
}
71+
}
72+
}
73+
5874
// Private
5975

6076
private var minimizeFontAnimation: FontAnimation!

TweeTextField/ViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ final class ViewController: UIViewController {
2222

2323
override func viewDidLoad() {
2424
super.viewDidLoad()
25+
usernameTextField.text = "text"
2526
}
2627

2728
@IBAction private func confirm() {

0 commit comments

Comments
 (0)