Skip to content
Mohamad Kaakati edited this page Sep 26, 2018 · 2 revisions

Login Form

form +++ Section("Login Form")
    <<< TextRow() { $0.placeholder = "Username" }
    <<< PasswordRow() { $0.placeholder = "Password" }
    <<< ButtonRow() {
        $0.title = "Login"
        $0.onCellSelection { cell, row in
            self.presentAlert(message: "Will login")
        }

Multiple Selection

form +++ Section("Multiple Choices")
    <<< MultipleSelectorRow<String>() {
        $0.title = "Favourite Foods"
        $0.options = ["🍝", "🍟", "πŸ•", "🍚"]
        $0.value = ["🍝", "πŸ•" ]
    }

Switch Show/Hide

<<< SwitchRow("switchRowTag"){
    $0.title = "Show message"
    }
    
<<< LabelRow(){
    $0.hidden = Condition.function(["switchRowTag"], { form in
        return !((form.rowBy(tag: "switchRowTag") as? SwitchRow)?.value ?? false)
    })
    $0.title = "Switch is on!"

Date Row

+++ Section("Section2")
<<< DateRow(){
    $0.title = "Date Row"
    $0.value = NSDate(timeIntervalSinceReferenceDate: 0) as Date
    }

Phone Row

<<< PhoneRow(){
    $0.title = "Phone Row"
    $0.placeholder = "And numbers here"
    }

Segmented Control

<<< SegmentedRow<String>("gender"){
    $0.options = ["male", "female"]
    $0.title = "m"
    $0.value = "f"
    }.onChange{ row in
        print(row.value)
    }

Text Row

form +++ Section("Section1")
    <<< TextRow(){ row in
        row.title = "Text Row"
        row.placeholder = "Enter text here"
}

Empty Section / Zero Height

// Section
+++ Section() {
   $0.header = HeaderFooterView<UIView>(HeaderFooterProvider.class)
   $0.header?.height = { CGFloat.leastNormalMagnitude }
   }

Multiple Selection

Adding more than one SelectableSection<ListCheckRow<String>> will require unique tag identifier for each.

form
    +++
    SelectableSection<ListCheckRow<String>>("Where did you travel?", selectionType: .multipleSelection){section in
        section.tag = Int(arc4random_uniform(9999999)).string // Unique Random Tag Identifer
}

let singleItems = ["Netherlands", "France", "Lebanon", "Cyprus"]
for option in singleItems {
    form.last! <<< ListCheckRow<String>(option){ listRow in
        listRow.title = option
        listRow.selectableValue = option
        listRow.value = nil
    }
}

Single Selection

Adding more than one SelectableSection<ListCheckRow<String>> will require unique tag identifier for each.

form
    +++
    SelectableSection<ListCheckRow<String>>("Single Selection?", selectionType: .singleSelection(enableDeselection: true)){section in
        section.tag = Int(arc4random_uniform(9999999)).string // Unique Random Tag Identifer
}

let singleItems2 = ["Netherlands", "France", "Lebanon", "Cyprus"]
for option in singleItems2 {
    form.last! <<< ListCheckRow<String>(){ listRow in
        listRow.tag = Int(arc4random_uniform(9999999)).string
        listRow.title = option
        listRow.selectableValue = option
        listRow.value = nil
    }
}

Custom View Cell with Image (Requires ViewRow from Community)

https://github.com/EurekaCommunity/ViewRow

form
    +++ Section() {
        $0.header = HeaderFooterView<UIView>(HeaderFooterProvider.class)
        $0.header?.height = { CGFloat.leastNormalMagnitude }
    }
    <<< ViewRow<UIView>() { (row) in
        
        }
        .cellSetup { (cell, row) in
            //  Construct the view - in this instance the a rudimentry view created here
            cell.view = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 210))
            cell.view!.backgroundColor = .white
            
            let imageContainer = UIImageView()
            cell.view!.addSubview(imageContainer)
            
            imageContainer.contentMode = .scaleAspectFill
            imageContainer.clipsToBounds = true
            imageContainer.anchor(top: cell.view!.topAnchor, left: cell.view!.leftAnchor, bottom: cell.view!.bottomAnchor, right: cell.view!.rightAnchor, topConstant: 0, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: 0, heightConstant: 210)
            imageContainer.image = UIImage(named: "") // Set Image Name
            
            cell.viewRightMargin = 0
            cell.viewLeftMargin = 0
            cell.viewTopMargin = 0
            cell.viewBottomMargin = 0
            cell.update()
        }