欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2023-11-22 23:42:58
第一种方法: 第二种方法: ......

 

第一种方法:

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

  

第二种方法:

  //字体大小
  textField.attributedPlaceholder = NSAttributedString.init(string:"输入你需要的服务", attributes: [NSFontAttributeName:UIFont.systemFont(ofSize:15)])
  //字体颜色
  textField.attributedPlaceholder = NSAttributedString.init(string:"输入你需要的服务", attributes: [
  NSForegroundColorAttributeName:UIColor.red])