Swift framework for creating dynamic forms.
Simple and easy to implement iOS Swift framework for building forms. It is builded on top of UICollectionViewController
component.
Supports 4 basic types of form elements:
FormElementTitle
(top title label of the form)FormElementButton
(subclass ofUIButton
control)FormElementTextField
(subclass ofUITextField
control)FormElementLabel
(subclass ofUILabel
control)
- Xcode 10.2
- Swift 5.0
# Podfile
use_frameworks!
target 'YOUR_TARGET_NAME' do
pod 'DSForm'
end
Replace YOUR_TARGET_NAME
and then, in the Podfile
directory, type:
$ pod install
- Create new
UICollectionVewController
and make it subbclass ofFormCollectionViewController
. - Set the
formDelegate
toself
inviewDidLoad()
method so we can use the protocolFormDelegate
methods in our class.
import UIKit
import DSForm
class ViewController: FormCollectionViewController, FormDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let element1 = FormElementTitle(text: "Please Sign Up")
let element2 = FormElementTextField(text: "Username")
let element3 = FormElementTextField(text: "Password")
let element4 = FormElementButton(title: "Sign Up")
fields = [element1, element2, element3, element4]
formDelegate = self
}
func didSubmitForm(fields: [String : String]) {
print(fields)
}
}
DSForm supports 4 basic form elements inside our collection:
It defines the title of the form and it is a subclass of the standard UILabel
control.
let element1 = FormElementTitle(text: "Please Sign Up")
FormElementTitle
available public properties:
public var font: UIFont
public var identifier: String
public var backgroundColor: UIColor
public var fontColor: UIColor
public var text: String
Supports user input and it is a subclass of the standard UITextField
control.
var element2 = FormElementTextField(text: "Username")
element2.topLabel = "Username"
FormElementTextField
available public properties:
public var font: UIFont
public var identifier: String
public var backgroundColor: UIColor
public var fontColor: UIColor
public var topLabel: String
public var placeholder: String
public var validation: DSForm.FormValidation
public var text: String
Subclass of the standard UIButton
control.
let element4 = FormElementButton(title: "Sign Up")
FormElementButton
available public properties:
public var font: UIFont
public var identifier: String
public var backgroundColor: UIColor
public var fontColor: UIColor
public var title: String
Subclass of the standard UILabel
control.
let element5 = FormElementLabel(text: "Sample text")
FormElementLabel
available public properties:
public var font: UIFont
public var identifier: String
public var backgroundColor: UIColor
public var fontColor: UIColor
public var text: String
- Reference the delegate property with @IBOutlet for easy connection from Xcode interface builder
- Add support for more form elements and variations (image, checkmark, radio button etc...)
- Add validation to
UITextField
(phone number, email address, numbers, regex, password etc...) - Add more styles to form elements
- Add more Unit Tests
- Add detailed documentation for every new feature
- Add blank space (element) between form elements
- Added element size property
- Added
CollectionView
UIEdgeInsets
property - Added placeholder text to
FormElementTextField
- Added new
.Line
style toFormElementTextField