一个iOS表单框架-UFKit

效果:

使用:

 pod 'UFKit'
 
 - (void)viewDidLoad {
    [super viewDidLoad];

    __block UFFormView *formView = [UFFormView makeFormView:^(UFFormViewMaker * _Nonnull make) {
        make
        .addSection([UFSection makeSection:^(UFSectionMaker * _Nonnull make) {
            make
            .addRow([UFAvatarRow makeAvatarRow:^(UFAvatarRowMaker * _Nonnull make) {
                make
                .cornerRadius(30)
                .avatarImage([UIImage imageNamed:@"touxiang"])
                .avatarDidSelected(^(__kindof UFAvatarRow * _Nonnull row, UIImageView * _Nonnull avatarView) {
                    NSLog(@"你点击了头像");
                })
                .title(@"头像")
                .value(@"http://img0.imgtn.bdimg.com/it/u=2572957358,1108684168&fm=26&gp=0.jpg")
                .name(@"avatar")
                .accessoryType(UFRowAccessorySpace);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .title(@"姓名")
                .value(@"苹果")
                .name(@"name")
                .accessoryType(UFRowAccessorySpace);
            }])
            .addRow([UFRadioGroupRow makeRadioGroupRow:^(UFRadioGroupRowMaker * _Nonnull make) {
                make
                .itemArray(@[@"男",@"女"])
                .title(@"性别")
                .value(@"男")
                .name(@"gender")
                .accessoryType(UFRowAccessorySpace);
            }])
            .addRow([UFTextFieldRow makeTextFieldRow:^(UFTextFieldRowMaker * _Nonnull make) {
                make
                .maxLength(11)
                .regex(@"^[1][3-9]*$")
                .keyboardType(UIKeyboardTypeNumberPad)
                .title(@"联系方式")
                .name(@"mobile")
                .accessoryType(UFRowAccessorySpace);
            }])
            .addRow([UFMobileCodeRow makeCodeRow:^(UFCodeRowMaker * _Nonnull make) {
                make
                .codeStyle([UFMobileCodeStyle makeMobileCodeStyle:^(UFMobileCodeStyleMaker * _Nonnull make) {

                }])
                .codeDidClicked(^(__kindof UFMobileCodeRow * _Nonnull row, UIButton * _Nonnull button) {
                    NSLog(@"点了了获取验证码");
                })
                .maxLength(4)
                .keyboardType(UIKeyboardTypeNumberPad)
                .title(@"验证码")
                .name(@"code")
                .accessoryType(UFRowAccessorySpace);
            }])
            .addRow([UFPickerViewRow makePickerViewRow:^(UFPickerViewRowMaker * _Nonnull make) {
                make
                .itemArray(@[@"iOS",@"macOS",@"swift",@"iPhone",@"iPad",@"iPod"])
                .title(@"技能")
                .value(@"iOS")
                .name(@"skills")
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFMultiplePickerViewRow makeMultiplePickerViewRow:^(UFMultiplePickerViewRowMaker * _Nonnull make) {
                make
                .itemArray(@[@"看电影",@"旅游",@"看书",@"打游戏",@"篮球",@"足球",@"其他"])
                .title(@"爱好")
                .value(@"打游戏,其他")
                .name(@"hobby")
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFDatePickerRow makeDatePickerRow:^(UFDatePickerRowMaker * _Nonnull make) {
                make
                .datePickerMode(UIDatePickerModeDate)
                .dateFormat(@"yyyy-MM-dd")
                .title(@"生日")
                .name(@"birthday")
                .accessoryType(UFRowAccessoryDisclosureIndicator);
            }])
            .addRow([UFSwitchRow makeSwitchRow:^(UFSwitchRowMaker * _Nonnull make) {
                make
                .tintColor([UIColor redColor])
                .title(@"免打扰")
                .value(SWITCH_ON)
                .name(@"allow")
                .accessoryType(UFRowAccessorySpace)
                .valueDidChanged(^(__kindof UFRow * _Nonnull row, __kindof NSString * _Nonnull value) {
                    if ([row.value boolValue]) {
                        NSLog(@"开");
                    } else {
                        NSLog(@"关");
                    }
                });
            }])
            .addRow([UFPlateNumberRow makePlateNumberRow:^(UFPlateNumberRowMaker * _Nonnull make) {
                make
                .title(@"车牌号")
                .value(@"鲁A123456")
                .name(@"plate")
                .accessoryType(UFRowAccessorySpace);
            }])
            .addRow([UFTextViewRow makeTextViewRow:^(UFTextViewRowMaker * _Nonnull make) {
                make
                .maxLength(120)
                .title(@"个人简介")
                .value(@"苹果公司是美国一家高科技公司。由史蒂夫·乔布斯、斯蒂夫·沃兹尼亚克和罗·韦恩等人于1976年4月1日创立,总部位于加利福尼亚州的库比蒂诺")
                .name(@"introduction")
                .accessoryType(UFRowAccessorySpace);
            }]);
        }])
        .addSubmitButton([UFActionButton makeActionButton:^(UFActionButtonMaker * _Nonnull make) {
            make
            .titleForState(@"提交", UIControlStateNormal)
            .titleColorForState([UIColor whiteColor], UIControlStateNormal)
            .cornerRadius(17)
            .backgroundColor([UIColor redColor])
            .actionButtonClick(^(UFActionButton * _Nonnull button) {
                NSLog(@"提交的信息:\n%@",[formView toDictionary]);
            });
        }])
        .addToSuperView(self.view);
    }];

    [formView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(self.view);
    }];
}

 
复制代码

依赖:

'Masonry', '~> 1.1.0'

'SDWebImage', '~> 5.0.6'

'IQKeyboardManager', '~> 6.3.0'

github

转载于:https://juejin.im/post/5d39753b518825634532565d

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值