Adding placeholder type attributes to a textField stringValue

Hi all,


I'm trying to find the easiest way to make text in a textField appear ghosted, giving it the same look as the placeholder text. I have a textfield that the user will enter text into, which then must be locked before any further functions are available. Making the textfield uneditable is easy, but getting the text to appear ghosted alludes me. Any help or pointers will be much appreciated.

Accepted Reply

>> Making the textfield uneditable is easy


By setting "isEditable" to false? That works, but it doesn't change the appearance of the text. I would suggest using the inherited "isEnabled" property instead, which (IIRC) will make the text appear "dimmed".


If that doesn't work, then notice that NSTextField has a "textColor" property. You can set this to (say) light gray to make the text look disabled.


(I answered this about NSTextField, since you talked about "stringValue", which is macOS only. UITextField also has "isEnabled" and "textColor" properties, so the answer applies to iOS if that's what you meant.)

Replies

>> Making the textfield uneditable is easy


By setting "isEditable" to false? That works, but it doesn't change the appearance of the text. I would suggest using the inherited "isEnabled" property instead, which (IIRC) will make the text appear "dimmed".


If that doesn't work, then notice that NSTextField has a "textColor" property. You can set this to (say) light gray to make the text look disabled.


(I answered this about NSTextField, since you talked about "stringValue", which is macOS only. UITextField also has "isEnabled" and "textColor" properties, so the answer applies to iOS if that's what you meant.)

Thanks, Quincy. Such a simple solution that I should have discovered myself. I actually used isEnabled the first time I set up the button but for some reason changed it to isEditable. Silly me didn't enter any text the first time, so I wasn't aware that it actually dimmed the text.


Cheers

Richard