From c5ba9fd861c1ea2330925dab3dc6a0f880dfaba5 Mon Sep 17 00:00:00 2001 From: justinmann Date: Sat, 10 Sep 2022 10:37:54 -0700 Subject: [PATCH 1/2] add placeholder color --- Sources/iTextField/iTextField+ViewModifiers.swift | 11 +++++++++++ Sources/iTextField/iTextField.swift | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Sources/iTextField/iTextField+ViewModifiers.swift b/Sources/iTextField/iTextField+ViewModifiers.swift index 5d81823..263ce13 100644 --- a/Sources/iTextField/iTextField+ViewModifiers.swift +++ b/Sources/iTextField/iTextField+ViewModifiers.swift @@ -54,6 +54,17 @@ extension iTextField { } return view } + + /// Modifies the **placeholder color** 🌈 of the text field 🖱 💬 + /// - Parameter placeholderColor: The color for placeholder 🎨 + /// - Returns: A text field with updated placeholder color 🚥🖍 + public func placeholderColor(_ placeholderColor: Color?) -> iTextField { + var view = self + if let placeholderColor = placeholderColor { + view.placeholderColor = UIColor.from(color: placeholderColor) + } + return view + } /// Modifies the **text alignment** of a text field. ⬅️ ↔️ ➡️ /// - Parameter alignment: The desired text alignment 👈👉 diff --git a/Sources/iTextField/iTextField.swift b/Sources/iTextField/iTextField.swift index 24f98ff..28108d0 100644 --- a/Sources/iTextField/iTextField.swift +++ b/Sources/iTextField/iTextField.swift @@ -26,6 +26,7 @@ public struct iTextField: UIViewRepresentable { var font: UIFont? var foregroundColor: UIColor? var accentColor: UIColor? + var placeholderColor: UIColor? var textAlignment: NSTextAlignment? var contentType: UITextContentType? @@ -73,7 +74,11 @@ public struct iTextField: UIViewRepresentable { private func setProperties(_ textField: UITextField) { // Accessing the Text Attributes textField.text = text - textField.placeholder = placeholder + if let placeholderColor = placeholderColor { + textField.attributedPlaceholder = NSAttributedString(string: placeholder, attributes: [.foregroundColor: placeholderColor]) + } else { + textField.placeholder = placeholder + } textField.font = font textField.textColor = foregroundColor if let textAlignment = textAlignment { From 72a97fa6807d118007a989c181d5a6789f2fc623 Mon Sep 17 00:00:00 2001 From: justinmann Date: Sat, 10 Sep 2022 11:06:59 -0700 Subject: [PATCH 2/2] delay changing first responder --- Sources/iTextField/iTextField.swift | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Sources/iTextField/iTextField.swift b/Sources/iTextField/iTextField.swift index 28108d0..37a021b 100644 --- a/Sources/iTextField/iTextField.swift +++ b/Sources/iTextField/iTextField.swift @@ -124,10 +124,12 @@ public struct iTextField: UIViewRepresentable { textField.isSecureTextEntry = isSecure // Managing the Editing Behavior - if isEditing.wrappedValue { - textField.becomeFirstResponder() + DispatchQueue.main.async { + if isEditing.wrappedValue { + textField.becomeFirstResponder() + } } - + textField.addTarget(context.coordinator, action: #selector(Coordinator.textFieldDidChange(_:)), for: .editingChanged) return textField @@ -167,10 +169,12 @@ public struct iTextField: UIViewRepresentable { } } - if isEditing.wrappedValue { - textField.becomeFirstResponder() - } else { - textField.resignFirstResponder() + DispatchQueue.main.async { + if isEditing.wrappedValue { + textField.becomeFirstResponder() + } else { + textField.resignFirstResponder() + } } }