最佳答案
您提供的代码运行良好,问题出在其他地方。您应该使用默认的 init with frame 而不是必需的 init,或者创建具有所需属性的便利 init。
class ThemeTextFieldCollab : UITextField {
override init(frame: CGRect) {
super.init(frame: frame)
self.attributedPlaceholder = NSAttributedString(string: self.placeholder ?? "", attributes: [NSForegroundColorAttributeName : UIColor.gray])
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
关于swift - 如何在 Swift 3 中修复我的自定义 UITextField 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54237243/