Last active
May 20, 2016 13:57
-
-
Save GE-N/89c3b9d7f20b4058914c to your computer and use it in GitHub Desktop.
Change UITextField's placeholder text colour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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