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!
Asked
Active
Viewed 1,435 times
-2
-
1You 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
-
1Possible 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 Answers
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