A dialog alert prompt that accepts a text input from the user and handles it via a delegate, using Swift.
pod 'VercettiPrompt'
Basic | Customized |
---|---|
Custom Buttons | Yummy |
Instantiate View Controller and setup transition variables.
You can copy this directly if you want(hint: yes you do).
let textPromptVC = TextInputPromptViewController.instantiateFromStoryboard()
textPromptVC.modalPresentationStyle = .custom
let vercettiTransistionDelegate = VercettiTransistionDelegate()
textPromptVC.transitioningDelegate = vercettiTransistionDelegate
Set the title, description if needed and present the dialog
textPromptVC.titleText = "The wheels of the bus go round and round"
textPromptVC.positiveButtonText = "Confirm"
textPromptVC.descriptionText = "Round and round"
present(textPromptVC, animated: true, completion: nil)
The property names are pretty self explanatory. Theres a table at the bottom for all the properties.
//USE THE BARE MINIMUM CODE FROM ABOVE FIRST
textPromptVC.positiveButtonText = "Confirm"
textPromptVC.placeholderText = "All day long"
textPromptVC.isTextMandatory = true
textPromptVC.descriptionText = "Round and round"
textPromptVC.titleFont = UIFont.boldSystemFont(ofSize: 28)
textPromptVC.descriptionFont = UIFont.systemFont(ofSize: 18)
textPromptVC.titleColor = UIColor.red
textPromptVC.descriptionColor = UIColor.blue
We got solid buttons and bordered buttons. Choose your poison.
Here's the enum for button types.
public enum ButtonType {
case bordered(borderColor: UIColor?, borderRadius: CGFloat?, textColor: UIColor?, borderWidth: CGFloat?)
case solid(backgroundColor: UIColor, textColor: UIColor?)
}
You can pass whatever values you feel are needed. The rest can be passed off as nil
.
textPromptVC.negativeButtonType = ButtonType.bordered(borderColor: UIColor.gray, borderRadius: 5, textColor: UIColor.red, borderWidth: 2)
textPromptVC.positiveButtonType = ButtonType.solid(backgroundColor: UIColor.blue, textColor: UIColor.white)
Download the demo project to play around with the properties. You might wanna do the pod install thingy to get it to run.
Name | Description |
---|---|
positiveButtonText | Text for the positiive action button |
negativeButtonText | Text for the negative action button |
placeholderText | Placeholder for the input text field |
characterLimit | Max allowed character length for the text field |
captitalizationType | Type of capitalization for the text field |
inputText | Pre-filled text for the text field |
descriptionText | Text for the Subtitle |
hideNegativeButton | Bool to hide the negative action button |
isTextMandatory | Bool to allow skipping input |
titleFont | Title Font |
descriptionFont | Subtitle Font |
positiveButtonFont | Font for the positive action button |
negativeButtonFont | Font for the negative action button |
textFieldBorderStyle | Border style for the text field |
titleColor | Title Color |
descriptionColor | Subtitle Color |
disabledPositiveButtonColor | Button Color for when the text is mandatory and the input is empty |