I would like to put a red asterix( * ) besides placeholder in ios in the registration form where i am using the uitextfield. I know how to change the placeholder color but in my requirement i have the placeholder color as grey with red asterix( * ) following it. How to achieve this in swift 3? Is it possible to set it in storyboard itself?
Asked
Active
Viewed 3,120 times
1
-
you can set image on textfield. – Rince Thomas May 10 '17 at 07:56
-
so how to hide the image on typing the uitextfield? – Michelle Root May 10 '17 at 07:58
-
This might help you: http://stackoverflow.com/a/13695462/3927536 – Otávio May 10 '17 at 07:58
-
check for shouldChangeCharactersInRange delegate method – Rince Thomas May 10 '17 at 08:00
1 Answers
2
You can use the built-in, attributedPlaceholder
property of UITextField
.
Like this:
let passwordAttriburedString = NSMutableAttributedString(string: "Password")
let asterix = NSAttributedString(string: "*", attributes: [.foregroundColor: UIColor.red])
passwordAttriburedString.append(asterix)
self.textField.attributedPlaceholder = passwordAttriburedString

Ronak Patel
- 609
- 4
- 16

dilaver
- 674
- 3
- 17