swift修改UITextfield的Placeholder字体大小和颜色

第一种方法:

self.userNumber.setValue(UIColor.lightGray, forKey: "_placeholderLabel.textColor")

self.userNumber.setValue(UIFont.systemFont(ofSize: 15), forKeyPath: "_placeholderLabel.font")



第二种方法:

  //字体大小

  textField.attributedPlaceholder = NSAttributedString.init(string:"输入你需要的服务", attributes: [NSAttributedString.Key.font:UIFont.systemFont(ofSize:15)])

  //字体颜色

  textField.attributedPlaceholder = NSAttributedString.init(string:"输入你需要的服务", attributes: [

  NSForegroundColorAttributeName:UIColor.red])

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容