Skip to content
This repository was archived by the owner on Apr 9, 2025. It is now read-only.
Open
Show file tree
Hide file tree
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
11 changes: 11 additions & 0 deletions Sources/iTextField/iTextField+ViewModifiers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 👈👉
Expand Down
25 changes: 17 additions & 8 deletions Sources/iTextField/iTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -119,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
Expand Down Expand Up @@ -162,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()
}
}
}

Expand Down