ZFJFormKit,经过整合数据和事件为一个Model来配置不一样类型的Cell来动态设置UITableView。git
ZFJFormKit | 地址 |
---|---|
项目地址 | github.com/zfjsyqk/ZFJ… |
Demo地址: | gitee.com/zfj1128/ZFJ… |
博客地址: | zfj1128.blog.csdn.net/article/det… |
主要经过ZFJFormModel来配置每个Cell,这里面能够配置Cell的值和事件;还能够经过ZFJFormCellConfig来配置Cell的通用属性,固然也能够为每一个不一样的Cell设置不一样的ZFJFormCellConfig, ZFJFormConfig类主要用于设置ZFJFormTableView的相关属性;项目的因此Cell都继承于ZFJFormCell; ZFJFormKit经过ZFJFormCell、ZFJFormModel和ZFJFormCellConfig来设置ZFJFormCell,而后又经过ZFJFormConfig来配置ZFJFormTableView,经过ZFJFormCell和ZFJFormTableView来实现咱们想要的表单Form。 ZFJPlacehoderTextView是自定义带占位符placeholder的textView。 具体结构图以下: github
ZFJFormKit包含6中CELL类型,具体类型以下:数组
typedef NS_ENUM(NSInteger, ZFJFormCellType) {
KFormCellLabelType = 0, //信息展现
KFormCellHeadImgType = 1, //右边头像
KFormCellTextFieldType = 2, //单行输入
KFormCellTextViewType = 3, //多行输入
KFormCellSwitchType = 4, //右侧开关
KFormCellCustomType = 5 //自定义CELL
};
复制代码
//CELL的通用配置Model,也能够根据不一样的CELL分别配置
ZFJFormCellConfig *configModel = [[ZFJFormCellConfig alloc] init];
//左边title
configModel.titleColor = [UIColor blackColor];
configModel.titleFont = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
//头像圆角尺寸
configModel.headImgRadius = 5;
//CELL右边值得颜色和字体
configModel.valueColor = [UIColor blueColor];
configModel.valueFont = [UIFont fontWithName:@"PingFangSC-Regular" size:16];
//分割线的配置
configModel.separatorLineColor = [UIColor groupTableViewBackgroundColor];
configModel.isHiddenLine = NO;
//占位符颜色
configModel.placeholderColor = [UIColor colorWithRed:0.776 green:0.776 blue:0.800 alpha:1.00];
//控件左右两边的间距
configModel.marginSize = 15;
复制代码
//姓名 不能修改,因此不能输入
ZFJFormModel *name_model = [[ZFJFormModel alloc] init];
name_model.formCellType = KFormCellLabelType;
name_model.configModel = _configModel;
name_model.title = @"姓名";
name_model.value = @"张福杰";
name_model.height = 50;
[self.dataArray addObject:name_model];
复制代码
/**
头像(UIImage或者NSString或者NSData)
*/
@property (nonatomic,strong) NSObject *iconObject;
复制代码
ZFJFormModel *headImg_model = [[ZFJFormModel alloc] init];
//CELL类型
headImg_model.formCellType = KFormCellHeadImgType;
//CELL的通用配置Model,也能够根据不一样的CELL分别配置
headImg_model.configModel = configModel;
headImg_model.title = @"头像";
headImg_model.iconObject = @"https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1561278644354&di=3cc92ef55c2336b29b1fe09cbf614705&imgtype=0&src=http%3A%2F%2Fimg4q.duitang.com%2Fuploads%2Fitem%2F201408%2F08%2F20140808171354_XkhfE.jpeg";
headImg_model.height = 100;
headImg_model.isCanSelect = YES;
headImg_model.isShowCellRightImg = YES;
[self.dataArray addObject:headImg_model];
复制代码
//昵称(单行输入 KFormCellTextFieldType)
ZFJFormModel *nickName_model = [[ZFJFormModel alloc] init];
nickName_model.formCellType = KFormCellTextFieldType;
nickName_model.configModel = configModel;
nickName_model.title = @"昵称";
nickName_model.placeholder = @"请输入您的昵称";
nickName_model.height = 50;
nickName_model.validateBlock = ^BOOL(ZFJFormModel * _Nullable model) {
if(model.value <= 0){
[MBProgressHUD SHOWPrompttext:model.placeholder];
return NO;
}
return YES;
};
[self.dataArray addObject:nickName_model];
复制代码
//我的简介(KFormCellTextViewType 多行输入)
ZFJFormModel *introduction_model = [[ZFJFormModel alloc] init];
introduction_model.formCellType = KFormCellTextViewType;
introduction_model.configModel = configModel;
introduction_model.title = @"我的简介";
introduction_model.placeholder = @"请输入您的我的简介";
introduction_model.height = 50;
introduction_model.textView_maxHeight = 100;
introduction_model.validateBlock = ^BOOL(ZFJFormModel * _Nullable model) {
if(model.value <= 0){
[MBProgressHUD SHOWPrompttext:model.placeholder];
return NO;
}
return YES;
};
[self.dataArray addObject:introduction_model];
复制代码
//选择器(KFormCellSwitchType)
ZFJFormModel *switch_model = [[ZFJFormModel alloc] init];
switch_model.formCellType = KFormCellSwitchType;
switch_model.configModel = configModel;
switch_model.title = @"是否开启好友推荐";
switch_model.placeholder = @"请选择";
switch_model.height = 50;
switch_model.validateBlock = ^BOOL(ZFJFormModel * _Nullable model) {
if(model.value == nil){
[MBProgressHUD SHOWPrompttext:model.placeholder];
return NO;
}
return YES;
};
[self.dataArray addObject:switch_model];
复制代码
//自定义CELL(KFormCellCustomType 保存)
ZFJFormModel *custom_model = [[ZFJFormModel alloc] init];
custom_model.formCellType = KFormCellCustomType;
custom_model.configModel = configModel;
custom_model.customCls = [SaveCell class];
custom_model.height = 120;
custom_model.isCanSelect = YES;
//自定义CELL事件处理
custom_model.customCellEventBlock = ^(id _Nonnull obj) {
NSLog(@"obj == %@",obj);
[ZFJFormTool validateDataArray:self.dataArray];
};
[self.dataArray addObject:custom_model];
复制代码
自定义Cell的设置以下:bash
- (void)configCellWithModel:(ZFJFormModel *)model{
NSLog(@"aaaaaaa");
_model = model;
}
- (void)saveBtnClick:(UIButton *)button{
//自定义CELL的事件处理
if(_model != nil && _model.customCellEventBlock){
_model.customCellEventBlock(button);
}
}
复制代码
- (ZFJFormTableView *)tableView{
if (_tableView == nil){
ZFJFormConfig *formConfig = [[ZFJFormConfig alloc] init];
formConfig.backgroundColor = [UIColor groupTableViewBackgroundColor];
_tableView = [[ZFJFormTableView alloc] initWithFrame:CGRectMake(0, KNavBarHei, ZFJForm_ScreenWidth, ZFJForm_ScreenHeight - KNavBarHei) config:formConfig];
}
return _tableView;
}
复制代码
事件处理接收架构
_tableView.didSelectRowBlock = ^(NSIndexPath * _Nullable indexPath, ZFJFormModel * _Nullable model) {
NSLog(@"%@",model);
};
复制代码
[ZFJFormTool validateDataArray:self.dataArray];
复制代码
- (ZFJPlacehoderTextView *)textView{
if(_textView == nil){
_textView = [[ZFJPlacehoderTextView alloc] init];
_textView.font = [UIFont systemFontOfSize:14];
_textView.delegate = self;
_textView.textAlignment = NSTextAlignmentRight;
_textView.placeholder = @"这是提示文字";
}
return _textView;
}
复制代码
闲来无事,把我在上个项目中本身封装表单配置框架抽出来,封装拿给你们使用,也欢迎各位大神提出宝贵的意见和建议,也欢迎你们进群交流365152048!框架