Skip to content

Instantly share code, notes, and snippets.

@appyaaron
Last active August 31, 2015 06:06
Show Gist options
  • Save appyaaron/9d7a09d33b173ec49ca1 to your computer and use it in GitHub Desktop.
Save appyaaron/9d7a09d33b173ec49ca1 to your computer and use it in GitHub Desktop.
A custom UITextField that allows you to easily set the placeholder color from your storyboard!
import UIKit
@IBDesignable class CustomTextField: UITextField {
@IBInspectable var placeholderColor: UIColor = UIColor.lightGrayColor() {
didSet {
let canEditPlaceholderColor = self.respondsToSelector(Selector("setAttributedPlaceholder:"))
if (canEditPlaceholderColor) {
self.attributedPlaceholder = NSAttributedString(string: placeholder, attributes:[NSForegroundColorAttributeName: placeholderColor]);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment