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

Attributed text support #328

Open
wants to merge 3 commits 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
22 changes: 21 additions & 1 deletion Sources/SkyFloatingLabelTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
// MARK: Colors

fileprivate var cachedTextColor: UIColor?
fileprivate var cachedAttributedText: NSAttributedString?

/// A UIColor value that determines the text color of the editable text
@IBInspectable
Expand All @@ -76,6 +77,21 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
}
}

/// An `NSAttributedString` to display as the text field content
///
/// **NOTE:** by setting this property to a non-nil value, changes to `textColor`
/// are ignored.
@IBInspectable
override dynamic open var attributedText: NSAttributedString? {
set {
cachedAttributedText = newValue
super.attributedText = newValue
}
get {
return cachedAttributedText
}
}

/// A UIColor value that determines text color of the placeholder label
@IBInspectable dynamic open var placeholderColor: UIColor = UIColor.lightGray {
didSet {
Expand Down Expand Up @@ -526,7 +542,11 @@ open class SkyFloatingLabelTextField: UITextField { // swiftlint:disable:this ty
} else if hasErrorMessage {
super.textColor = textErrorColor ?? errorColor
} else {
super.textColor = cachedTextColor
if let attributedText = cachedAttributedText {
super.attributedText = attributedText
} else {
super.textColor = cachedTextColor
}
}
}

Expand Down