Closed chriskilpin closed 1 year ago
If you use the configuration system to get direct access to the underlying UITextField
you can set an attributedPlaceholder
instead, which is the only way you can change the placeholder styling as far as I'm aware.
I wasn’t aware you could get access to the underlying textfield, I will give that a try. Thanks for getting back to me.
Thanks that worked!
I don't want to reopen this issue but wanted to ask a clarifying question. When I do something like this, the placeholder string is blank.
$0.attributedPlaceholder = NSAttributedString(
string: "Placeholder",
attributes: [NSAttributedString.Key.foregroundColor: UIColor.gray]
)
Is the right use of this library to set the placeholder text and use the attributedPlaceholder
for applying the color, or would you normally expect just setting the attributedPlaceholder
to work?
@mergesort I would expect setting the attributed placeholder to work, I'm not sure why it wouldn't. 😕
Sorry, just dug in a little bit more and realized that this is likely because ResponsiveTextField
initializer has a mandatory parameter of placeholder
which I've defaulted to ""
. Though that's my implementation, I don't see a way to have an overriding attributedPlaceholder
, since the library will use whatever placeholder
you pass in as a parameter.
Ah, in that case it might need a change to make the placeholder
parameter an optional string and only set it if it is non-nil, which should allow you to set the attributed placeholder instead. I'd accept a PR :)
Duly noted, will try to sneak that in for ya!
Hmm, I thought marking placeholder as optional would do the trick since UITextField.placeholder
is actually String?
out the box but I'm still not seeing an attributedPlaceholder
being drawn after this commit.
Hmm, according to the docs it might not actually be possible to change the placeholder colour anyway: https://developer.apple.com/documentation/uikit/uitextfield/1619610-attributedplaceholder
This property is nil by default. If set, the placeholder string is drawn using system-defined color and the remaining style information (except the text color) of the attributed string
So strange. I find myself able to change the placeholder color by changing both properties, but maybe it's a hack that this works when done in tandem?
I'll put this into a pull request but I've gone ahead and added a new responsiveTextFieldPlaceholderColor
which satisfies my need of being able to update the placeholder text color.
It may not be exactly the approach you're looking for so I'm happy to make changes for more general purposes, but it seemed like a good idea if the main purpose is to update the placeholder text, and in line with the APIs you've exposed.
Hi Luke. Thanks for a great library. Was wondering if it is possible to change the colour of the placeholder text?