Search code examples
iosswiftcolorsuitextfield

How to change all TextField border colour in Swift 3


How can I change all TextField border colour in Swift 3? I've built one iPad application with many TextFields in my .xib file and now I want to change border colour, but it seems like so many lines to write a particular textfield


Solution

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