本文主要是介绍[Swift]UITextFiled设置占位提示文字(placeholderColor)的颜色,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
方式一
codeTextField.attributedPlaceholder = "请输入验证码".attributesColor(UIColor(hexString: "#727C95"), UIFont.systemFont(ofSize: 15))
import Foundationextension String {/// 富文本/// - Parameters:/// - color: 颜色 默认黑色/// - font: 字体大小 默认17/// - Returns: 富文本func attributesColor(_ color: UIColor = .black, _ font: UIFont = .systemFont(ofSize: 17)) -> NSAttributedString {let attri = NSMutableAttributedString(string: self)attri.addAttributes([.foregroundColor: color], range: NSRange(location: 0, length: self.count))attri.addAttributes([.font: font], range: NSRange(location: 0, length: self.count))return attri}}
方式二
codeTextField.placeHolderColor = UIColor(hexString: "#727C95")
import Foundationextension UITextField{@IBInspectable var placeHolderColor: UIColor? {get {return self.placeHolderColor}set {self.attributedPlaceholder = NSAttributedString(string:self.placeholder != nil ? self.placeholder! : "", attributes:[NSAttributedString.Key.foregroundColor: newValue!])}}
}
这篇关于[Swift]UITextFiled设置占位提示文字(placeholderColor)的颜色的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!