Search code examples
swiftobjectswift3uitextfield

How to fix my custom UITextField object in Swift 3?


I have issues when I'm trying to create a custom object (UITextField) in Swift 3, it didn't happen before.

enter image description here


Solution

  • The code you provided is working fine the problem is somewhere else. You should use the default init with frame instead of the required one, or create your convenience init with desired properties.

    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)
    
        }
    }