-2

I have a sample login page. In that, I have one textField. I want to change the alpha value(or opacity) of the textfield's placeholder text only. I searched on google but did not get an answer. Please Help!

Milan Nosáľ
  • 19,169
  • 4
  • 55
  • 90
Sneha Patil
  • 67
  • 1
  • 9
  • 1
    You can give it a color & alpha using attributed string. Refer this [answer] (https://stackoverflow.com/a/26076202/5620628) – Arpit Dongre Jan 18 '18 at 12:33
  • 1
    Possible duplicate of [Changing Placeholder Text Color with Swift](https://stackoverflow.com/questions/26076054/changing-placeholder-text-color-with-swift) – Olly Hodgson Jan 18 '18 at 15:47

1 Answers1

5

Just set the placeholder as an attributed string and set the color as you want it:

textField.attributedPlaceholder = NSAttributedString(string: "Placeholder", attributes: [NSAttributedStringKey.foregroundColor : UIColor.gray.withAlphaComponent(0.5)])
Milan Nosáľ
  • 19,169
  • 4
  • 55
  • 90