Search code examples
swiftios13xcode11

PlaceholderColor not set to PlaceHolderLabel for UITextfield in ios13


self.setValue(placeHolderColor, forKeyPath: "_placeholderLabel.textColor")

in ios13 its crashed.how to set placeholderColor to placeholderLabel in swift5 for ios13 in xcode11.


Solution

  • Set color using attributedPlaceholder as below,

    let colorAttrbs: [NSAttributedString.Key: Any] = [.foregroundColor: UIColor.red]
    textField.attributedPlaceholder = NSAttributedString(string: "placeholder", attributes: colorAttrbs)