@IBOutlet weak var tf: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
tf.placeholder ="user chen"
tf.setValue(UIColor.redColor(), forKeyPath: "_placeholderLabel.textColor")
tf.setValue(UIFont.systemFontOfSize(18), forKeyPath:"_placeholderLabel.font")
}
或者
tf.attributedPlaceholder = NSAttributedString(string: "。。。。", attributes: [NSFontAttributeName:UIFont.systemFontOfSize(14)])
需要注意的是placeHold默认的字号是和字体字号一样的,所以如果只调整placeHolder的字号可能会造成placeHolder偏上, 这时可以使用
override func drawPlaceholderInRect(rect: CGRect) { //...}
override func placeholderRectForBounds(bounds: CGRect) -> CGRect {//..}
方法根据需要调整成自己需要的。