ZFJFormKit-iOS专业表单配置框架

ZFJFormKit

介绍

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

image

安装教程

  1. pod 'ZFJFormKit'
  2. pod install
  3. 导入头文件#import "ZFJFormKit.h"

使用说明

ZFJFormKit包含6中CELL类型,具体类型以下:数组

typedef NS_ENUM(NSInteger, ZFJFormCellType) {
    KFormCellLabelType      = 0,    //信息展现
    KFormCellHeadImgType    = 1,    //右边头像
    KFormCellTextFieldType  = 2,    //单行输入
    KFormCellTextViewType   = 3,    //多行输入
    KFormCellSwitchType     = 4,    //右侧开关
    KFormCellCustomType     = 5     //自定义CELL
};
复制代码
  1. 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;
复制代码
  1. 文本信息展现 这里的不能修改也不是绝对意义上的不能修改,能够经过设置isCanSelect属性,而后在ZFJFormTableView的点击事件回调中didSelectRowBlock,从新设置model.value的值;
//姓名 不能修改,因此不能输入
    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];
复制代码
  1. 头像类型Cell设置 须要说明的是iconObject是NSObject类型,支持的类型有UIImage或者NSString或者NSData;这里面设置isCanSelect为YES,能够点击从新从相册里面设置新的图片,固然这个功能不仅仅只是用于头像功能,用户也能够根据本身的须要设置其余类型的image的cell;
/**
	 头像(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];
复制代码
  1. 单行输入
//昵称(单行输入 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];
复制代码
  1. 多行输入 多行输入能够设置最大高度textView_maxHeight,若是超过最大高度,则textView内就进行滚动展现,cell 的高度也不会增长;
//我的简介(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];
复制代码
  1. 选择器 这里选择器的打开或者关闭状态能够经过设置model.value来控制,当model.value==nil的时候,选择器从处于关闭状态,反之处于打开状态;
//选择器(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];
复制代码
  1. 自定义Cell 关于自定义cell,必定要注册cell类型,即传custom_model.customCls = [SaveCell class];SaveCell即为你自定义的cell,自定义cell能够设置ZFJFormCellDelegate代理,也能够不用设置; 若是自定义Cell有事件须要处理可使用custom_model.customCellEventBlock来接收事件和处理事件;
//自定义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);
    }
}
复制代码
  1. ZFJFormTableView配置
- (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);
        };
复制代码
  1. 值验证 值验证我提供了两个方法,一个验证一维数组,一个验证二维数组;使用以下(一维数组):
[ZFJFormTool validateDataArray:self.dataArray];
复制代码
  1. ZFJPlacehoderTextView ZFJPlacehoderTextView是自定义带占位符placeholder的textView,使用以下:
- (ZFJPlacehoderTextView *)textView{
    if(_textView == nil){
        _textView = [[ZFJPlacehoderTextView alloc] init];
        _textView.font = [UIFont systemFontOfSize:14];
        _textView.delegate = self;
        _textView.textAlignment = NSTextAlignmentRight;
        _textView.placeholder = @"这是提示文字";
    }
    return _textView;
}
复制代码

使用截图

image
image
image

结束语

闲来无事,把我在上个项目中本身封装表单配置框架抽出来,封装拿给你们使用,也欢迎各位大神提出宝贵的意见和建议,也欢迎你们进群交流365152048!框架

相关文章
相关标签/搜索