Search code examples
swiftuitextfieldborder

How to change border color of text field?


I am trying to change the border color of an UITextField, I cant find any option to change it in Main(base) and the code I am using in viewController is:

import UIKit

class ViewController: UIViewController {
    @IBOutlet weak var textsa: UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
        textsa.layer.backgroundColor = CGColor(red: 23, green: 23, blue: 23, alpha: 12.3)
    } 
}

Solution

  • You have to set the borderColor and borderWidth of the textfield 's layer:

    textsa?.layer.borderColor = UIColor.red.cgColor
    textsa?.layer.borderWidth = 2.0