The SingleLineInput framework provides a reusable component for creating single-line input fields in iOS applications. This framework simplifies the process of building user interfaces by offering a customizable and highly functional single-line input view.
Features
- Elegant and customizable design
- Supports various text input types
- Validation options for user input
- Auto-capitalization support
- Formatted text input using masks
- Automatic handling of keyboard appearance and dismissal
Installation
- Using Cocoapods:
- Manual installation:
- Download the latest release from the SingleLineInput GitHub repository.
- Copy the SingleLineInput.framework file to your project directory.
- Add the framework to your Xcode project.
pod 'SingleLineInput'
Usage
To use the SingleLineInput framework in your project:
- Add the following import statement to your Swift file:
- Create an instance of SingleLineInputView:
- Customize the input field as desired:
- Add the SingleLineInputView as a subview:
- Handle user input using the provided delegate methods:
import SingleLineInput
let singleLineInputView = SingleLineInputView(frame: CGRect(x: 0, y: 0, width: 200, height: 40))
singleLineInputView.placeholder = "Enter your name"
view.addSubview(singleLineInputView)
singleLineInputView.delegate = self
Customization
The SingleLineInput framework offers several customization options:
- Appearance: Change the appearance of the input field, including text color, background color, border styles, etc.
- Text Input Type: Select the type of textual input expected from the user (e.g., email, password, number, etc.).
- Validation: Validate user input according to specific criteria (e.g., email format, password complexity, etc.).
- Auto-capitalization: Determine whether the first letter of each word should automatically be capitalized.
- Formatted Input: Apply a format mask to enforce a specific input pattern (e.g., phone number format).
singleLineInputView.font = UIFont.systemFont(ofSize: 16)
singleLineInputView.textColor = UIColor.black
singleLineInputView.backgroundColor = UIColor.white
singleLineInputView.inputType = .emailAddress
singleLineInputView.validationType = .email
singleLineInputView.autoCapitalizationType = .words
singleLineInputView.formatMask = "###-###-####"
Delegate Methods
The SingleLineInputViewDelegate protocol defines the following methods:
inputDidChange(_ input: String)
: Called when the user input changes.textFieldShouldReturn()
: Called when the “Return” key is pressed.
extension ViewController: SingleLineInputViewDelegate {
func inputDidChange(_ input: String) {
// Handle input changes
}
func textFieldShouldReturn() {
// Handle return key press
}
}
Additional Notes
- This framework supports iOS 10 and later versions.
- For more details and examples, refer to the official SingleLineInput documentation on GitHub.