From 42d8965bf8707cb940d4da2a886cc8f63e5296d0 Mon Sep 17 00:00:00 2001 From: Swati Wadhera Date: Thu, 5 Sep 2019 11:16:47 +0530 Subject: [PATCH] added support for border color --- Sources/SkyFloatingLabelTextField.swift | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Sources/SkyFloatingLabelTextField.swift b/Sources/SkyFloatingLabelTextField.swift index 0578e8e..2e9e926 100644 --- a/Sources/SkyFloatingLabelTextField.swift +++ b/Sources/SkyFloatingLabelTextField.swift @@ -113,6 +113,20 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty updateTitleColor() } } + + /// A UIColor value that determines the border color of the textField when in the normal state + @IBInspectable dynamic open var borderColor: UIColor = .gray { + didSet { + updateBorderColor() + } + } + + /// A UIColor value that determines the border color of the textField when in the selected state + @IBInspectable dynamic open var selectedBorderColor: UIColor = .gray { + didSet { + updateBorderColor() + } + } /// A UIColor value that determines the color of the bottom line when in the normal state @IBInspectable dynamic open var lineColor: UIColor = .lightGray { @@ -467,6 +481,20 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty } } } + + fileprivate func updateBorderColor() { + if !isEnabled { + self.layer.borderColor = borderColor.cgColor + } else if hasErrorMessage { + self.layer.borderColor = borderColor.cgColor + } else { + if editingOrSelected || isHighlighted { + self.layer.borderColor = selectedBorderColor.cgColor + } else { + self.layer.borderColor = borderColor.cgColor + } + } + } fileprivate func updateTextColor() { if !isEnabled {