BonMot icon indicating copy to clipboard operation
BonMot copied to clipboard

UITextfield's placeholder color

Open amaurydavid opened this issue 8 years ago • 1 comments

In my UITextField, I want the placeholder and the text to use the same style. According to the doc, they both use the bonMotStyleproperty:

  • note: The style is applied to both the attributedText and attributedPlaceholder. If you plan on styling them differently, use attributed strings directly.

The issue here is that the style's color isn't correctly applied to the placeholder:

textField.bonMotStyle = StringStyle(.font(UIFont.systemFont(ofSize: 16)), .color(UIColor.red))

will result in a placeholder still being grey instead of red, but the text is correctly colored. Note: While the placeholder isn't colored, its font size is correctly set to 16 instead of 14.

However, a workaround can be to set the style to both bonMotStyle and attributedPlaceholder:

let style = StringStyle(.font(UIFont.systemFont(ofSize: 16)), .color(UIColor.red))
styledTextField.bonMotStyle = style
if let placeholder = styledTextField.placeholder {								
     styledTextField.attributedPlaceholder = style.attributedString(from: placeholder)
}

Tested with BonMot 5.0 on iOS 11.2 and 10.3.1

amaurydavid avatar Jan 04 '18 09:01 amaurydavid

I've got a fix but not sure the doc is accurate? It was last edited 2 years ago.

Should the placeholder text have the same style? From a HID perspective, it is conveying the wrong assumption that the placeholder is (text) data. Instead of adding code to match the doc, maybe update the doc to match the code?

pauluhn avatar Oct 02 '18 22:10 pauluhn