Fix placeholder of textfield

This commit is contained in:
ismailgulek
2020-09-11 16:39:32 +03:00
parent 5130059cc5
commit 7866ed7447
2 changed files with 21 additions and 0 deletions
@@ -24,6 +24,26 @@ class InsettedTextField: UITextField {
}
}
var placeholderColor: UIColor? {
didSet {
updateAttributedPlaceholder()
}
}
override var placeholder: String? {
didSet {
updateAttributedPlaceholder()
}
}
private func updateAttributedPlaceholder() {
guard let placeholder = placeholder else { return }
guard let color = placeholderColor else { return }
attributedPlaceholder = NSAttributedString(string: placeholder, attributes: [
NSAttributedString.Key.foregroundColor: color
])
}
override func placeholderRect(forBounds bounds: CGRect) -> CGRect {
return bounds.inset(by: insets)
}