这是 UITableViewDataSource/UITableViewDelegate
表单构造解决方案。它允许使用 UITableView/UITableViewCell
定制功能。我们提供了几个基本的 单元格。如果您没有找到特定的表单 UI 元素,可以轻松地使用熟悉的工具如 InterfaceBuilder(使用 cell xibs)或通过继承 UITableViewCell
来创建它。我们欢迎 pull-requests!
表单配置和逻辑可以以声明方式实现。可以放置在单独的模块中,在不同的视图控制器中重复使用。
您有两种方式尝试这个库:
$ git clone [email protected]:setoff/EasyForm.git
$ cd EasyForm/Example
$ pod install
$ open EasyForm.xcworkspace
或
$ pod try EasyForm
在工作区打开后,选择 EasyForm-Example
目标并运行应用。
EFForm
实现了 UITableViewDelegate
和 UITableViewDataSource
协议。因此,您可以轻松地将表单与任何 UITableView
实例一起使用。但建议与 UITableViewController
(或其子类)一起使用,因为有一些“免费”功能,如将滚动到 UITableViewCell
中的焦点文本框。
表单实现结构看起来像这样:
self.form = [EFForm new];
// Config form items
EFElement *input = [[EFElement alloc] initWithTag:@"inputField"
cellClass:[EFTextFieldCell class]];
input.setupCell = ^(UITableViewCell *cell) {
((EFTextFieldCell *)cell).textField.placeholder = @"Tap to start typing";
};
EFElement *switchElement = [[EFElement alloc] initWithTag:@"switch"
cellClass:[EFSwitchCell class]];
switchElement.setupCell = ^(UITableViewCell *cell) {
((EFSwitchCell *)cell).titleLabel.text = @"Cell with switch";
((EFSwitchCell *)cell).switchToggle.onTintColor = [EFExampleHelpers greenColor];
((EFSwitchCell *)cell).onToggle = ^(BOOL isOn) {
[self.presentingController alertAction:[NSString stringWithFormat:@"Toggle is %@",
isOn ? @"ON" : @"OFF"]];
};
};
// Config section and add form elements
EFSection *inputSection = [[EFSection alloc] initWithTag:@"predefined"
elements:@[input, switchElement]];
inputSection.title = @"Form section";
// Add sections to form
self.form.sections = @[inputSection];
[self.tableView displayForm:self.form];
EasyForm 可以通过 CocoaPods 获得。要安装它,只需将以下行添加到您的 Podfile
中:
pod "EasyForm"
EasyForm 在 MIT 许可下提供。有关更多信息,请参阅 LICENSE 文件。