这么基础的东西居然还要找好一会,做个记录:
继承UITextField
class GsTextField: UITextField {
}
override func drawPlaceholderInRect(rect: CGRect) {
if let placeholders = placeholder{
self.attributedPlaceholder =
NSAttributedString(string: placeholders,
attributes: [NSForegroundColorAttributeName:UIColor.whiteColor()])
}
super.drawPlaceholderInRect(rect)
}
或者在外面调用直接写
self.mTextField.attributedPlaceholder =NSAttributedString(string: placeholders, attributes: [NSForegroundColorAttributeName:UIColor.whiteColor()])