1

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?

click to see image

Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
Michelle Root
  • 185
  • 1
  • 3
  • 9

1 Answers1

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