适用于iPhone/iPad的动态表单 - iOS 6, 7及更高版本(受BZGFormViewController启发)。
现在与知名库JVFloatLabeledTextField集成。
BPFormViewController
BPFormCell
实现了BPFormCellProtocol
BPFormInputCell
- "抽象类"和所有输入单元格的基类BPFormInputTextFieldCell
使用BPFormTextField
BPFormFloatInputTextFieldCell
使用BPFormFloatLabelTextField
BPFormInputTextViewCell
使用BPFormTextView
BPFormFloatInputTextViewCell
使用BPFormFloatLabelTextView
BPFormButtonCell
BPFormInfoCell
实现了BPFormCellProtocol
BPAppearance
请查看详细的类图。
转到/Example,运行pod install
,然后在BPFormsExample.xcworkspace中运行目标
对于您创建的任何表单,您应该子类化BPFormViewController
或者实例化它。
您可以创建简单的输入单元格(BPFormInputTextFieldCell
)或带有标签浮在文本值上方(如截图所示的BPFormFloatInputTextFieldCell
)的输入单元格。
只需设置所需的属性并确保设置BPFormViewController
实例为textField
的代理。shouldChangeBlock
用于验证输入的数据,请添加验证代码(请参阅示例)。
BPFormFloatInputTextFieldCell *emailCell = [[BPFormFloatInputTextFieldCell alloc] init];
emailCell.textField.placeholder = @"Email";
emailCell.textField.delegate = self;
emailCell.customCellHeight = 50.0f;
emailCell.mandatory = YES;
emailCell.shouldChangeTextBlock =
BPValidateBlockWithPatternAndMessage(
@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}",
@"The email should look like [email protected]");
BPFormButtonCell *signUpCell = [[BPFormButtonCell alloc] init];
signUpCell.button.backgroundColor = [UIColor blueColor];
[signUpCell.button setTitle:@"Sign Up" forState:UIControlStateNormal];
signUpCell.button.layer.cornerRadius = 4.0;
signUpCell.button.layer.masksToBounds = YES;
signUpCell.buttonActionBlock = ^(void){
NSLog(@"Button pressed");
};
formCells
包含一个区域数组,每个区域包含其单元格self.formCells = @[@[emailCell, passwordCell, password2Cell, nameCell, phoneCell], @[signUpCell]];
[self setHeaderTitle:@"Please enter your credentials" forSection:0];
[self setFooterTitle:@"When you're done, press <<Sign Up>>" forSection:0];
// fonts
[BPAppearance sharedInstance].infoCellLabelFont = [UIFont systemFontOfSize:12];
// colors
[BPAppearance sharedInstance].headerFooterLabelTextColor = [UIColor lightGray];
// sizes
[BPAppearance sharedInstance].infoCellHeight = 25;