TextField - Tai-Kimura/SwiftJsonUI GitHub Wiki
TextField
class: SJUITextField inherites: UITextField
Platform Support
- ✅ UIKit: Full support (All attributes available)
- ✅ SwiftUI: Full support (All attributes available through DynamicComponent)
- ✅ Jetpack Compose: Full support (Maps to TextField composable)
- ✅ Android XML: Maps to
com.kotlinjsonui.views.KjuiEditText(custom EditText with font support)
Attributes for TextField
| attribute name | UIKit | SwiftUI | Compose | XML | type in json | details | remarks |
|---|---|---|---|---|---|---|---|
| text | ✅ | ✅ | ✅ | ✅ | string | Text value for textField | |
| font | ✅ | ✅ | ✅ | ✅ | string | Font name for textField | |
| fontSize | ✅ | ✅ | ✅ | ✅ | float | Font size for textField | |
| fontColor | ✅ | ✅ | ✅ | ✅ | string | textField.textColor | |
| hint | ✅ | ✅ | ✅ | ✅ | string | NSLocalizedString(hint, comment:"") will be set to textField.hint | |
| hintFont | ✅ | ✅ | ❌ | ❌ | string | Hint font name for textField | Dynamic mode only |
| hintFontSize | ✅ | ✅ | ❌ | ❌ | float | Hint font size for textField | Dynamic mode only |
| hintColor | ✅ | ✅ | ✅ | ✅ | string | Hint font color for hint | |
| fieldPadding | ✅ | ✅ | ❌ | ❌ | float | Right inner space for the textField | Dynamic mode only |
| textAlign | ✅ | ✅ | ✅ | ✅ | string | Text alignment: Left, Right, Center | |
| borderStyle | ✅ | ✅ | ✅ | ❌ | string | Border style: RoundedRect, Line, Bezel | |
| input | ✅ | ✅ | ✅ | ✅ | string | Keyboard type: alphabet, email, password, number, decimal | |
| returnKeyType | ✅ | ✅ | ✅ | ✅ | string | Return key type: Done, Next, Search, Send, Go, Route, Yahoo, Google | |
| onTextChange | ✅ | ✅ | ✅ | ❌ | string | UIControlEvents.editingChanged event selector | |
| secure | ✅ | ✅ | ✅ | ✅ | boolean | Secure text entry for passwords | |
| enabled | ✅ | ✅ | ✅ | ✅ | boolean/string | view.isEnabled. Can be boolean or @{variableName} | |
| userInteractionEnabled | ✅ | ✅ | ✅ | ❌ | boolean | Enable user interaction | |
| autocapitalizationType | ✅ | ✅ | ✅ | ✅ | string | Auto-capitalization type | |
| autocorrectionType | ✅ | ✅ | ✅ | ✅ | string | Auto-correction type | |
| spellCheckingType | ✅ | ✅ | ✅ | ✅ | string | Spell checking type | |
| keyboardAppearance | ✅ | ✅ | ✅ | ❌ | string | Keyboard appearance: dark, light | |
| clearButtonMode | ✅ | ✅ | ❌ | ❌ | string | Clear button mode | |
| leftView | ✅ | ❌ | ❌ | ❌ | JSON | Left view configuration | UIKit only |
| rightView | ✅ | ❌ | ❌ | ❌ | JSON | Right view configuration | UIKit only |
| leftViewMode | ✅ | ❌ | ❌ | ❌ | string | Left view display mode | UIKit only |
| rightViewMode | ✅ | ❌ | ❌ | ❌ | string | Right view display mode | UIKit only |
Attributes for input type 'number' and 'decimal'
| attribute name | UIKit | SwiftUI | Compose | XML | type in json | details | remarks |
|---|---|---|---|---|---|---|---|
| accessoryBackground | ✅ | ✅ | ❌ | ❌ | string | textField.inputAccessoryView.backgroundColor | Dynamic mode only |
| accessoryTextColor | ✅ | ✅ | ❌ | ❌ | string | Text color for label on textField.inputAccessoryView | Dynamic mode only |
| doneText | ✅ | ✅ | ❌ | ❌ | string | Text for label on textField.inputAccessoryView to resignFirstResponder | Dynamic mode only |
Protocols for TextField
SJUITextFieldDelegate
@objc public protocol SJUITextFieldDelegate
Delegate protocol for SJUITextField with additional functionality beyond UITextFieldDelegate.
@objc optional func textFieldDidDeleteBackward(textField: UITextField)
Called when the delete/backspace key is pressed. Useful for handling custom delete behavior.
Properties for TextField
Static Properties
open class var viewClass: SJUITextField.Type
This property will be used to decide which class to inflate with createFromJSON method. You should define the view's class on this property when you create classes inheriting from SJUITextField.
static var accessoryBackgroundColor: UIColor
Background color for input accessory view (default: gray).
static var accessoryTextColor: UIColor
Text color for input accessory view labels (default: blue).
static var defaultBorderColor: UIColor
Default border color for text fields (default: lightGray).
Instance Properties
public var placeholderAttributes: [NSAttributedString.Key : Any]?
Attributes dictionary for styling the placeholder text, including font, color, and other text attributes.
private var _sjUiDelegate: SJUITextFieldDelegate?
Internal delegate reference that handles special events like delete key presses.
Override Properties
override var delegate: UITextFieldDelegate?
Custom delegate property that extends UITextFieldDelegate functionality with SJUITextFieldDelegate capabilities.
Functions for TextField
Static Methods
public class func createFromJSON(attr: JSON, target: Any, views: inout [String: UIView]) -> SJUITextField
Factory method called when the text field is created from JSON file. Override this method when you create classes inheriting from SJUITextField class.
Override Methods
override func deleteBackward()
Custom delete handling that calls the SJUITextFieldDelegate method textFieldDidDeleteBackward.
Provides additional callback functionality beyond standard UITextField behavior.
Inherited Methods
SJUITextField inherits all methods from UITextField and SJUIView, including:
- Text input and editing methods
- Event handling and delegate methods
- Layout constraint management
- Touch and gesture handling
- Keyboard and input accessory management
Event Handling
SJUITextField supports various input events:
onTextChangefor editingChanged events- Return key handling through
returnKeyType - Custom delete key handling through SJUITextFieldDelegate
- Input accessory view with "Done" button for number keyboards
- Integration with binding system for dynamic text updates