官方 2.1.1

Formal 2.1.1

测试已测试
Lang语言 SwiftSwift
许可 MIT
发布最新版本2018年1月
SwiftSwift版本3.0
SPM支持SPM

Meniny维护。



Formal 2.1.1

  • 作者:
  • Elias Abel

Formal

这是什么?

Formal 是一个 UITableView 表单构建器。

Formal

要求

  • iOS 8.0+
  • Xcode 8与Swift 3

依赖

贡献

您可以通过进行分支和提交拉取请求来为此库做出贡献。

许可

Formal 是开源软件,许可协议为 MIT

用法

准备

Formal 允许您通过 扩展 FormalViewController 来简单地添加部分和行。

class ViewController: FormalViewController {
    // ...
}

您可以通过设置自己的 Formal 属性来创建表单,而无需从 FormalViewController 扩展。

class ViewController: UIViewController: FormalDelegate {
    var formal: Formal = Formal()

    override func viewDidLoad() {
        super.viewDidLoad()
        formal.delegate = self
    }

    func sectionsHaveBeenAdded(_ sections: [FormalSection], at: IndexSet) {

    }
    func sectionsHaveBeenRemoved(_ sections: [FormalSection], at: IndexSet) {

    }
    func sectionsHaveBeenReplaced(oldSections: [FormalSection], newSections: [FormalSection], at: IndexSet) {

    }
    func rowsHaveBeenAdded(_ rows: [FormalBaseRow], at: [IndexPath]) {

    }
    func rowsHaveBeenRemoved(_ rows: [FormalBaseRow], at: [IndexPath]) {

    }
    func rowsHaveBeenReplaced(oldRows: [FormalBaseRow], newRows: [FormalBaseRow], at: [IndexPath]) {

    }
    func valueHasBeenChanged(for: FormalBaseRow, oldValue: Any?, newValue: Any?) {

    }
}

添加部分

formal +++ FormalSection("Base")
formal +++ FormalSection(header: "Acknowledgement", footer: "https://github.com/Meniny/Formal")
formal +++ FormalSection(header: "Setup", footer: "Footer", { section in
    // ...
})

添加行

formal +++ FormalSection("Base")
    <<< FormalTextRow() {
        $0.textType = .account
        $0.title = "Account"
        $0.placeholder = "Enter account here"
        $0.value = "Meniny"
}

全部删除

formal.removeAll()

改变动画

formal.animationSettings.rowInsertAnimation = .fade

文本字段行

public enum FormalTextType {
    case normal
    case phone
    case account
    case password
    case name
    case email
    case twitter
    case zipCode
}
formal +++ FormalSection("Base")
    <<< FormalTextRow() {
        $0.textType = .account
        $0.title = "Account"
        $0.placeholder = "Enter account here"
        $0.value = "Meniny"
    }
    <<< FormalTextRow() { row in
        row.textType = .password
        row.title = "Password"
        row.placeholder = "Enter password here"
    }
    <<< FormalTextRow(.email, tag: "Email", { (row) in
        row.title = "Email"
        row.placeholder = "Enter Email here"
    })
    <<< FormalTextRow(.twitter, tag: "Twitter", { (row) in
        row.title = "Twitter"
        row.placeholder = "Twitter Text here"
})

URL行

formal +++ FormalSection("Base")
    <<< FormalURLRow() { row in
        row.title = "URL"
        row.placeholder = "Enther URL here"
}

文本区域行

formal +++ FormalSection("Base")
    <<< FormalTextAreaRow() { row in
        row.placeholder = "TextArea"
}

格式化数字行

formal +++ FormalSection("Base")
    <<< FormalDecimalRow() { row in
        row.title = "Decimal"
        row.placeholder = "Enter decimal here"
}

开关行

formal +++ FormalSection("Base")
    <<< FormalSwitchRow() { row in
        row.title = "Switch"
        row.tag = "Switch"
}

按钮行

formal +++ FormalSection("Base")
    <<< FormalButtonRow() { row in
        row.title = "Button"
}

标签行

formal +++ FormalSection("Base")
    <<< FormalLabelRow() { row in
        row.title = "Label"
}

复选框行

formal +++ FormalSection("Base")
    <<< FormalCheckRow() { row in
        row.title = "Check"
        row.value = true
        }.onChange({ (row) in
            print("\(row.value!)")
        })
    <<< FormalImageCheckRow() { row in
        row.title = "Image Check"
        row.value = true
}

浮动文本字段/URL/格式化数字行

formal +++ FormalSection("Base")
    <<< FormalTextFloatingFieldRow() { row in
        row.placeholder = "Enter text here"
        row.value = "Floating Text Field"
    }
    <<< FormalURLFloatingFieldRow() { row in
        row.placeholder = "Enter URL here"
        row.value = URL(string: "https://meniny.cn/")
}

步进器行

formal +++ FormalSection("Base")
    <<< FormalStepperRow() { row in
        row.title = "Stepper"
        row.value = 2
    }

位置行

formal +++ FormalSection("Base")
    <<< FormalLocationRow() { row in
        row.title = "Location"
    }

通用密码行

formal +++ FormalSection("Base")
    <<< FormalGenericPasswordRow() { row in
        let password = "[ABCdef123]"
        row.placeholder = "Generic Password \(password)"
        row.value = password
    }

滑块行

formal +++ FormalSection("Base")
    <<< FormalSliderRow() { row in
        row.title = "Slider"
}

分割行

formal +++ FormalSection("Options")
    <<< FormalSegmentedRow<String>() { row in
        row.title = "Segmented"
        row.options = options
}

推选器行

formal +++ FormalSection("Options")
    <<< FormalPushSelectorRow<String>() { row in
        row.title = "Push"
        row.options = options
}

弹出选择器行

formal +++ FormalSection("Options")
    <<< FormalPopoverSelectorRow<String>() { row in
        row.title = "Popover"
        row.options = options
}

内联选择器行

formal +++ FormalSection("Options")
    <<< FormalPickerInlineRow<String>() { row in
        row.title = "Picker Inline"
        row.options = options
    }
    <<< FormalDateInlineRow() { row in
        row.title = "Date Inline"
    }
    <<< FormalPickerRow<String>() { row in
        var opts = [String]()
        for i in 0...5 {
            opts.append("Picker \(i)")
        }
        row.options = opts
}

操作表行

formal +++ FormalSection("Options")
    <<< FormalActionSheetRow<String>() { row in
        row.title = "ActionSheet"
        row.options = options
}

警告行

formal +++ FormalSection("Options")
    <<< FormalAlertRow<String>() { row in
        row.title = "Alert"
        row.options = options
}

输入选择器行

formal +++ FormalSection("Options")
    <<< FormalPickerInputRow<String>("Picker Input Row") { row in
        row.title = "PickerInput"
        row.options = []
        for i in 1...10 {
            row.options.append("PickerInput \(i)")
        }
        row.value = row.options.first
    }
    <<< FormalPhotoPickerRow() { row in
        row.title = "Image"
}

隐藏部分和行

使用 FormalCondition 隐藏/显示部分和行。

formal +++ FormalSection("Testing", { (section) in
    section.tag = "TestingSection"
    section.hidden = FormalCondition.closure(tags: ["HidingSwitch"], closure: { (f) -> Bool in
        if let r = f.rowBy(tag: "HidingSwitch") as? FormalSwitchRow {
            return r.value ?? false
        }
        return false
    })
})
    <<< FormalLabelRow() {
        $0.title = "Home"
        $0.value = "https://github.com/Formal"
}
formal +++ FormalSection("Hiding")
    <<< FormalSwitchRow("HidingSwitch") { row in
        row.title = "Hide Testings Section"
        row.value = false
}

查阅示例项目以获取更多详细信息。