Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for border color #298

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Sources/SkyFloatingLabelTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down