How to change all TextField border colour in Swift 3

Harshil Kotecha picture Harshil Kotecha · Mar 27, 2017 · Viewed 7.4k times · Source

How to change all TextField border colour in Swift 3 i build one iPad application. i have many TextField in my .xib file and now i want to change border colour but it so many line to write particular textfield so any sort way for this ?

Answer

RajeshKumar R picture RajeshKumar R · Mar 27, 2017

Add this extension to create border for all textfields in your project.

extension UITextField
{
    open override func draw(_ rect: CGRect) {
        self.layer.cornerRadius = 3.0
        self.layer.borderWidth = 1.0
        self.layer.borderColor = UIColor.lightGray.cgColor
        self.layer.masksToBounds = true
    }
}