iOS XLForm框架的使用

iOS XLForm框架的使用_第1张图片
还款日.png

1.创建一个继承于XLFormViewController的控制器

@interface BankCardInformationViewController : XLFormViewController

2.实现3个方法

-(instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self initializeForm];
    }
    return self;
}

-(instancetype)init
{
    self = [super init];
    if (self){
        [self initializeForm];
    }
    return self;
}

-(void)initializeForm
{

}

3.创建单元格

-(void)initializeForm
{
    //创建表单
    XLFormDescriptor * form = [XLFormDescriptor formDescriptor];
    //创建组
    XLFormSectionDescriptor * section = [XLFormSectionDescriptor formSection];
    //创建行
    XLFormRowDescriptor * row = [XLFormRowDescriptor formRowDescriptorWithTag:@"securityCode"   rowType:XLFormRowDescriptorTypePhone title:@"安全码"];
    //单元格高度
    row.height = 60;
    //设置占位文本颜色
    [row.cellConfigAtConfigure setObject:@"卡背面末三位"  forKey:@"textField.placeholder" ];
    //限制输入的字数
    [row.cellConfigAtConfigure setObject:@(3) forKey:@"textFieldMaxNumberOfCharacters"];
    //设置标题颜色
    [row.cellConfig setObject:[UIColor blackColor] forKey:@"textLabel.textColor"];
    //添加到组上
    [section addFormRow:row];
    [form addFormSection:section];
    self.form = form;
}

4.获取输入的值

NSDictionary *dict = [self.form formValues];

5.根据输入的值改变按钮背景颜色

-(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
{
    NSDictionary *dict = [self.form formValues];
    NSLog(@"%@",dict);
    // super implmentation MUST be called
    [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
    if (![dict[@"idCard"] isEqual:[NSNull null]] && ![dict[@"phone"] isEqual:[NSNull null]] && ![dict[@"securityCode"] isEqual:[NSNull null]] && ![dict[@"validity"] isEqualToString:@"信用卡有效期"]) {
        self.nextBtn.enabled = YES;
        self.nextBtn.backgroundColor = RGBColor(223, 97, 98, 1);
    }else{
        self.nextBtn.enabled = NO;
        self.nextBtn.backgroundColor = RGBColor(222, 222, 222, 1);
    }
}

6.自定义cell

#import "ValidityCell.h"

@implementation ValidityCell

NSString * const Validity = @"Validity";


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
+(void)load
{
    [XLFormViewController.cellClassesForRowDescriptorTypes setObject:[ValidityCell class] forKey: Validity];
}
//初始化所有对象
- (void)configure{

}
//更新单元当它将要呈现
- (void)update
{
    [super update];

}

//点击单元格时调用
- (void)formDescriptorCellDidSelectedWithFormController:(XLFormViewController *)controller{

}

6.给cell赋值

//self.repayPeriods(是XLFormRowDescriptor对象)

[self.repayPeriods.cellConfig setObject:day  forKey:@"_payDay" ];
//刷新单元格
 [self reloadFormRow:self.repayPeriods];

你可能感兴趣的:(iOS XLForm框架的使用)