swift修改UITextfield的Placeholder字体
2017-06-27 本文已影响737人
轮子糙
**//第一种 **
let textField = UITextField.init()
textField.placeholder = placehold
//字体大小
textField.setValue(UIFont.systemFont(ofSize: 15),forKeyPath: "_placeholderLabel.font")
//字体颜色
textField.setValue(UIFont.systemFont(ofSize: 15), forKeyPath: "_placeholderLabel.textColor")
//第二种
//字体大小
textField.attributedPlaceholder = NSAttributedString.init(string:"输入你需要的服务", attributes: [NSFontAttributeName:UIFont.systemFont(ofSize:15)])
//字体颜色
textField.attributedPlaceholder = NSAttributedString.init(string:"输入你需要的服务", attributes: [ NSForegroundColorAttributeName:UIColor.red])