Skip to content

Instantly share code, notes, and snippets.

@GE-N
Last active May 20, 2016 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save GE-N/89c3b9d7f20b4058914c to your computer and use it in GitHub Desktop.
Save GE-N/89c3b9d7f20b4058914c to your computer and use it in GitHub Desktop.
Change UITextField's placeholder text colour
extension UITextField {
public override func drawPlaceholderInRect(rect: CGRect) {
let newColor = UIColor(white: 1, alpha: 0.4)
let range = NSMakeRange(0, self.attributedPlaceholder!.length)
var mutatedAttributedPlaceholder = NSMutableAttributedString(attributedString: self.attributedPlaceholder!)
mutatedAttributedPlaceholder.setAttributes([ NSForegroundColorAttributeName : newColor ], range: range)
self.attributedPlaceholder = mutatedAttributedPlaceholder
super.drawPlaceholderInRect(rect)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment