How to change UITextField placeholder color in Swift 3 and Interface Builder

You can change UITextField placeholder color programmatically or using interface builder

Changing UITextField placeholder color in Swift 3

1- Create a new UITextField subclass and  override its

layoutSubviews() and insert in it this line of code

self.setValue(UIColor.init(red: 178/255.0, green: 34/255.0, blue: 78/255.0, alpha: 0.5), forKeyPath: "_placeholderLabel.textColor")

Continue reading “How to change UITextField placeholder color in Swift 3 and Interface Builder”

How to add underline to UITextField in Swift 3

UITextField Underlined In Swift 3

Create a custom UITexField and add this method to it then override

layoutSubviews() and call it from there

    func underlined(){
        let border = CALayer()
        let lineWidth = CGFloat(0.3)
        border.borderColor = UIColor.lightGray.cgColor
        border.frame = CGRect(x: 0, y: self.frame.size.height - lineWidth, width:  self.frame.size.width, height: self.frame.size.height)
        border.borderWidth = lineWidth
        self.layer.addSublayer(border)
        self.layer.masksToBounds = true
    }

Good to know How to change UITextField placeholder color