Fix placeholder of textfield

This commit is contained in:
ismailgulek 2020-09-11 16:39:32 +03:00
parent ba7b27bdc4
commit 82c62265c5
2 changed files with 21 additions and 0 deletions

View file

@ -30,6 +30,7 @@ extension TextFieldTableViewCell: Themable {
func update(theme: Theme) {
theme.applyStyle(onTextField: textField)
textField.placeholderColor = theme.placeholderTextColor
}
}

View file

@ -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)
}