You can set the placeholder text using an attributed string. Pass the color you want with the attributes
:
var myTextField = UITextField(frame: CGRect(x: 0, y: 0, width: 200, height: 30))
myTextField.backgroundColor = .blue
myTextField.attributedPlaceholder = NSAttributedString(string: "placeholder text",
attributes: [NSForegroundColorAttributeName: UIColor.yellow])
For Swift 3+ use following:
myTextField.attributedPlaceholder = NSAttributedString(string: "placeholder text",
attributes: [NSAttributedStringKey.foregroundColor: UIColor.white])
For Swift 4.2 use following:
myTextField.attributedPlaceholder = NSAttributedString(string: "placeholder text",
attributes: [NSAttributedString.Key.foregroundColor: UIColor.white])
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…