我必须创建一个自定义类来在XIB中设计textField,并在我的viewController中多次重用它。我想以编程方式更改每个占位符名称。
发布于 2019-03-25 18:20:26
创建子类为:
class CustomTextField: UITextField {
override func awakeFromNib() {
super.awakeFromNib()
}
func placeHolderColor(pColor: UIColor, pText: String) {
self.attributedPlaceholder = NSAttributedString(string: pText,
attributes: [NSAttributedStringKey.foregroundColor: pColor])
}
}发布于 2019-03-25 17:33:48
在您的文本字段自定义类中声明一个字符串类型的开放变量。访问该变量以更改曾经实现过的占位符名称。
发布于 2019-03-25 17:37:21
您可以通过以下两种方式进行更改
1) yourTextField.placeholder = "some string"
2) yourTextField.attributedPlaceholder = NSAttributedString(string: "some string")
https://stackoverflow.com/questions/55334748
复制相似问题