Skip to content

A Protocol Oriented Programming approach to form creation written in Swift

Notifications You must be signed in to change notification settings

bikisDesign-zz/Swift_POP_Form

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Carthage compatible

POP! A form builder written in Swift

A basic form creation system that uses MVVM and POP to quickly create and customize iOS forms

It uses SwiftValidator and for it's validation

Documentation

Regularly updated documentation can be found here bikisdesign.github.io/Swift_POP_Form

Quick Start Guide

Let's start by creating a textfield's datasource:

private struct FirstName_Field: PopFormFieldDataSource {
  var prefilledText: String?

  var theme: PopFormFieldTheme = TextFieldTheme()

  var placeholder: String = "First Name"

  var apiKey: String = "firstName"

  var validationRule: [Rule]? = [RequiredRule(message: "First Name is Required")]

  var returnKey: UIReturnKeyType? = .next

  var autoCapitilization: UITextAutocapitalizationType = .words
}

We can even do date pickers or custom picker views as inputViews

private struct BirthdayDatePickerDataSource: PopFormDatePickerDataSource {
  var startDate: Date? = nil

  var restrictedDateRange: (Date, Date)? = nil

  var shouldPrefillStartDate: Bool = false

  var formatForDisplayedDate: (Date) -> String = {
    let df = DateFormatter()
    df.dateFormat = "MM"
    let month = df.string(from: $0)
    df.dateFormat = "dd"
    let day = df.string(from: $0)
    df.dateFormat = "yy"
    let year = df.string(from: $0)
    return "\(day).\(month).\(year)"
  }
}

Then add some field styling:

private struct TextFieldTheme: PopFormFieldTheme {

  var focusedColor: UIColor = UIColor.lightGray

  var textfieldFont: UIFont = UIFont.systemFont(ofSize: 15, weight: .light)
  
  var borderOpacity: Float = 0.85
  
  var textAlignment: NSTextAlignment = .center
  
  var borderIsUnderline: Bool = false
  
  var errorColor: UIColor = .red
  
  var backgroundColor: UIColor = UIColor.white
  
  var textColor: UIColor = UIColor.black
  
  var placeholderTextColor: UIColor = UIColor.lightGray
  
  var borderColor: UIColor = UIColor.lightGray
  
  var borderWidth: CGFloat = 0.5
  
  var height: CGFloat = 65

  var textFieldHeight: CGFloat = 60

  var textViewHeight: CGFloat = 120

  var cursorColor: UIColor = UIColor.blue
}

Now add styling for the form itself:

private struct FormTheme: PopFormTheme {
  var backgroundColor: UIColor = .white
  var formColor: UIColor = .white
}

Now create your form:

struct PersonalInformationForm: PopFormDataSource {
  var fields: PopFormFields = [FirstName_Field(),
                               LastName_Field(),
                               Zip_Field(),
                               PhoneNumber_Field(),
                               Occupation_Field(),
                               Notes_Field(),
                               Birthday_Field()]
  
  var theme: PopFormTheme = FormTheme()
}

Lastly, create an instance of a PopFormViewController and pass the form datasource to it:

private lazy var formVC: PopFormViewController = {
    let f = PopFormViewController(dataSource: formDataSource)
    f.delegate = selfreturn f
  }()

Sucess Demo Fail Demo

About

A Protocol Oriented Programming approach to form creation written in Swift

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages