ZFJFormKit

introduce

ZFJFormKit, which dynamically sets up a UITableView by combining data and events into a Model to configure different types of cells.

ZFJFormKit address
The project address Github.com/zfjsyqk/ZFJ…
The Demo address: Gitee.com/zfj1128/ZFJ…
Blog Address: Zfj1128.blog.csdn.net/article/det…

Software architecture

ZFJFormModel is used to configure each Cell, which can configure the value and event of the Cell. The ZFJFormCellConfig class is mainly used to set the ZFJFormTableView properties. The ZFJFormCellConfig class is used to set the ZFJFormTableView properties. All the project cells inherit from ZFJFormCell; ZFJFormKit uses ZFJFormCell, ZFJFormModel, and ZFJFormCellConfig to set ZFJFormCell, and then ZFJFormConfig to set ZFJFormTableView, Use ZFJFormCell and ZFJFormTableView to implement the Form we want. ZFJPlacehoderTextView is a custom textView with placeholder PLACEHOLDER. The specific structure diagram is as follows:

Install the tutorial

  1. pod ‘ZFJFormKit’
  2. pod install
  3. #import “zfjformKit.h”

Directions for use

ZFJFormKit contains six CELL types as follows:

Typedef NS_ENUM(NSInteger, ZFJFormCellType) {KFormCellLabelType = 0, // // Enter KFormCellTextViewType = 3, // Enter KFormCellSwitchType = 4, KFormCellCustomType = 5 // Custom CELL};Copy the code
  1. Cell Common Configuration
ZFJFormCellConfig *configModel = [[ZFJFormCellConfig alloc] init]; TitleColor = [UIColor blackColor]; configModel.titleFont = [UIFont fontWithName:@"PingFangSC-Regular" size:16]; / / head rounded size configModel. HeadImgRadius = 5; Configmodel.valuecolor = [UIColor blueColor]; configModel.valueFont = [UIFont fontWithName:@"PingFangSC-Regular" size:16]; / / line configuration configModel. SeparatorLineColor = [UIColor groupTableViewBackgroundColor]; configModel.isHiddenLine = NO; / / placeholder color configModel. PlaceholderColor = [UIColor colorWithRed: green 0.776:0.776 blue: alpha 0.800:1.00]; // Spacing between the left and right sides of the control configmodel.marginsize = 15;Copy the code
  1. Text information display

You can do this by setting the isCanSelect property and then resetting the model.value in the ZFJFormTableView hit event callback didSelectRowBlock;

ZFJFormModel *name_model = [[ZFJFormModel alloc] init]; name_model.formCellType = KFormCellLabelType; name_model.configModel = _configModel; Name_model. title = @" name "; Name_model. value = @" "; name_model.height = 50; [self.dataArray addObject:name_model];Copy the code
  1. Profile picture type Cell setting

It’s important to note that iconObject is an NSObject, and it supports UIImage or NSString or NSData; Set isCanSelect to YES, you can click to set a new image from the album. Of course, this function is not only used for the image function, users can also set other types of image cells according to their own needs.

/** avatar (UIImage or NSString or NSData) */ @property (nonatomic,strong) NSObject *iconObject;Copy the code
ZFJFormModel *headImg_model = [[ZFJFormModel alloc] init]; //CELL type headimg_model. formCellType = KFormCellHeadImgType; Headimg_model. configModel = configModel; headimg_model. configModel = configModel; Headimg_model. title = @" avatar "; 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];Copy the code
  1. A single input
// nickname (single-line KFormCellTextFieldType) ZFJFormModel *nickName_model = [[ZFJFormModel alloc] init]; nickName_model.formCellType = KFormCellTextFieldType; nickName_model.configModel = configModel; Nickname_model. title = @" nickname "; Nickname_model.placeholder = @" Please enter your nickname "; 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];Copy the code
  1. Multiline input

Multi-line input can set the maximum height of textView_maxHeight. If the maximum height is exceeded, textView will scroll and the cell height will not increase.

ZFJFormModel * introduction_Model = [[ZFJFormModel alloc] init]; introduction_model.formCellType = KFormCellTextViewType; introduction_model.configModel = configModel; Introduction_model. title = @" Introduction "; Introduction_model. placeholder = @" Please input your profile "; 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];Copy the code
  1. The selector

Value ==nil. When model.value==nil, the selector is in the closed state, and vice versa.

// selector (KFormCellSwitchType) ZFJFormModel *switch_model = [[ZFJFormModel alloc] init]; switch_model.formCellType = KFormCellSwitchType; switch_model.configModel = configModel; Switch_model. title = @" Whether to enable friend recommendation "; Table_model. placeholder = @" select "; 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];Copy the code
  1. Custom Cell

Custom_model.customcls = [SaveCell class]; custom_model.customCls = [SaveCell class]; SaveCell is your own cell, which can be set as ZFJFormCellDelegate or not. If you have any events need to deal with custom Cell can use custom_model. CustomCellEventBlock to receive and handle events;

// Customize CELL (KFormCellCustomType save) 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; . / / custom CELL event handling custom_model customCellEventBlock = ^ (id _Nonnull obj) {NSLog (@ "obj = = % @", obj); [ZFJFormTool validateDataArray:self.dataArray]; }; [self.dataArray addObject:custom_model];Copy the code

The configuration of a custom Cell is as follows:

- (void)configCellWithModel:(ZFJFormModel *)model{ NSLog(@"aaaaaaa"); _model = model; } - (void)saveBtnClick:(UIButton *)button{// customize CELL event handling if(_model! = nil && _model.customCellEventBlock){ _model.customCellEventBlock(button); }}Copy the code
  1. ZFJFormTableView configuration
- (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;
}
Copy the code

Event processing reception

_tableView.didSelectRowBlock = ^(NSIndexPath * _Nullable indexPath, ZFJFormModel * _Nullable model) {
            NSLog(@"%@",model);
        };
Copy the code
  1. Value verification

Value validation I provide two methods, one to validate a one-dimensional array and one to validate a two-dimensional array; Use the following (one-dimensional array) :

[ZFJFormTool validateDataArray:self.dataArray];
Copy the code
  1. ZFJPlacehoderTextView

ZFJPlacehoderTextView is a custom textView with placeholder placeholder placeholder.

- (ZFJPlacehoderTextView *)textView{ if(_textView == nil){ _textView = [[ZFJPlacehoderTextView alloc] init]; _textView.font = [UIFont systemFontOfSize:14]; _textView.delegate = self; _textView.textAlignment = NSTextAlignmentRight; _textView.placeholder = @" This is the prompt text "; } return _textView; }Copy the code

Use the screenshot

conclusion

Have nothing to do, I in the last project in their own packaging form configuration framework out, packaging for everyone to use, but also welcome you to put forward valuable comments and suggestions!