2

Let say I have a text like this "By signing up I agree to the Terms of use and Privacy policy of Rue.Du.8 " inside a UITextField , I want to make the whole color Grey except "Terms of use" as white color . Is it possible to achieve into a UITextField?

enter image description here

Thanks in advance ...

Nirav D
  • 71,513
  • 12
  • 161
  • 183
Arafin Russell
  • 1,487
  • 1
  • 18
  • 37
  • see this http://stackoverflow.com/questions/27728466/use-multiple-font-colors-in-a-single-label-swift – Anbu.Karthik Aug 13 '16 at 09:31
  • I would use a text view so you can make the terms of use and privacy links work. Text fields don't have that functionality. – Dan Levy Aug 13 '16 at 11:53

1 Answers1

5

You can do this using the attributedPlaceholder property, first create an AttributedString, like this.

var str = "By signing up I agree to the Terms of use and Privacy policy of Rue.Du.8"
var attributedString = NSMutableAttributedString(string: str)
attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.grayColor(), range: (str as NSString).rangeOfString(str))
attributedString.addAttribute(NSForegroundColorAttributeName, value: UIColor.whiteColor(), range: (str as NSString).rangeOfString("Terms of use"))
self.textField.attributedPlaceholder = attributedString 
Nirav D
  • 71,513
  • 12
  • 161
  • 183