![【移动应用开发技术】XLForm怎么在iOS中使用_第1页](http://file4.renrendoc.com/view/8a9717c4a1ce560dbc761281d48c9344/8a9717c4a1ce560dbc761281d48c93441.gif)
![【移动应用开发技术】XLForm怎么在iOS中使用_第2页](http://file4.renrendoc.com/view/8a9717c4a1ce560dbc761281d48c9344/8a9717c4a1ce560dbc761281d48c93442.gif)
![【移动应用开发技术】XLForm怎么在iOS中使用_第3页](http://file4.renrendoc.com/view/8a9717c4a1ce560dbc761281d48c9344/8a9717c4a1ce560dbc761281d48c93443.gif)
![【移动应用开发技术】XLForm怎么在iOS中使用_第4页](http://file4.renrendoc.com/view/8a9717c4a1ce560dbc761281d48c9344/8a9717c4a1ce560dbc761281d48c93444.gif)
![【移动应用开发技术】XLForm怎么在iOS中使用_第5页](http://file4.renrendoc.com/view/8a9717c4a1ce560dbc761281d48c9344/8a9717c4a1ce560dbc761281d48c93445.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
【移动应用开发技术】XLForm怎么在iOS中使用
本篇文章给大家分享的是有关XLForm怎么在iOS中使用,在下觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着在下一起来看看吧。一、导入项目使用CocoaPods或者手动导入库文件,本人选择直接导入项目源文件的方式。
导入项目.png二、改造表单ViewController让ViewController继承自XLFormViewController,并重写下面的两个方法@interface
OneViewController
:
XLFormViewController
@end
@implementation
OneViewController
-
(instancetype)initWithNibName:(NSString
*)nibNameOrNil
bundle:(NSBundle
*)nibBundleOrNil
{
self
=
[super
initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if
(self){
[self
initializeForm];
}
return
self;
}
-
(id)initWithCoder:(NSCoder
*)aDecoder
{
self
=
[super
initWithCoder:aDecoder];
if
(self){
[self
initializeForm];
}
return
self;
}
@end三、构造表单-
(void)initializeForm
{
//
设置是否显示Cell之间分界线
//self.tableView.separatorStyle
=
UITableViewCellSeparatorStyleNone;
//
设置Section的高度
self.tableView.sectionHeaderHeight
=
30;
XLFormDescriptor
*
form;//form,一个表单只有一个
XLFormSectionDescriptor
*
section;//section,一个表单可能有多个
XLFormRowDescriptor
*
row;
//row,每个section可能有多个row
//
Form
form
=
[XLFormDescriptor
formDescriptor];
//
First
section
section
=
[XLFormSectionDescriptor
formSection];
section.title
=
@"用户";
[form
addFormSection:section];
//
普通文本
row
=
[XLFormRowDescriptor
formRowDescriptorWithTag:@"username"
rowType:XLFormRowDescriptorTypeText];
//
设置placeholder
[row.cellConfig
setObject:@"用户名"
forKey:@"textField.placeholder"];
//
设置文本颜色
[row.cellConfig
setObject:[UIColor
redColor]
forKey:@"textField.textColor"];
[section
addFormRow:row];
//
密码
row
=
[XLFormRowDescriptor
formRowDescriptorWithTag:@"password"
rowType:XLFormRowDescriptorTypePassword];
//
设置placeholder的颜色
NSAttributedString
*attrString
=
[[NSAttributedString
alloc]
initWithString:@"密码"
attributes:
@{NSForegroundColorAttributeName:[UIColor
greenColor],
}];
[row.cellConfig
setObject:attrString
forKey:@"textField.attributedPlaceholder"];
[section
addFormRow:row];
//
Second
Section
section
=
[XLFormSectionDescriptor
formSection];
section.title
=
@"日期";
[form
addFormSection:section];
//
日期选择器
row
=
[XLFormRowDescriptor
formRowDescriptorWithTag:@"birthday"
rowType:XLFormRowDescriptorTypeDate
title:@"出生日期"];
row.value
=
[NSDate
dateWithTimeIntervalSinceNow:60*60*24];
[section
addFormRow:row];
//
Third
Section
section
=
[XLFormSectionDescriptor
formSection];
section.title
=
@"头像";
[form
addFormSection:section];
//
图片选择
row
=
[XLFormRowDescriptor
formRowDescriptorWithTag:@"userpic"
rowType:XLFormRowDescriptorTypeImage];
[section
addFormRow:row];
//
Fourth
Section
section
=
[XLFormSectionDescriptor
formSection];
section.title
=
@"选择器";
[form
addFormSection:section];
//
选择器
row
=
[XLFormRowDescriptor
formRowDescriptorWithTag:@"sex"
rowType:XLFormRowDescriptorTypeSelectorPush];
row.noValueDisplayText
=
@"暂无";
row.selectorTitle
=
@"性别选择";
row.selectorOptions
=
@[@"男",@"女",@"其他"];
row.title
=
@"性别";
[row.cellConfigForSelector
setObject:[UIColor
redColor]
forKey:@"textLabel.textColor"];
[row.cellConfigForSelector
setObject:[UIColor
greenColor]
forKey:@"detailTextLabel.textColor"];
[section
addFormRow:row];
//
Fifth
Section
section
=
[XLFormSectionDescriptor
formSection];
section.title
=
@"加固";
[form
addFormSection:section];
//
开关
row
=
[XLFormRowDescriptor
formRowDescriptorWithTag:@"enforce"
rowType:XLFormRowDescriptorTypeBooleanSwitch
title:@"加固"];
[section
addFormRow:row];
//
Sixth
Section
section
=
[XLFormSectionDescriptor
formSection];
[form
addFormSection:section];
//
按钮
row
=
[XLFormRowDescriptor
formRowDescriptorWithTag:@"conform"
rowType:XLFormRowDescriptorTypeButton];
row.title
=
@"确定";
[section
addFormRow:row];
self.form
=
form;
}
-(void)didSelectFormRow:(XLFormRowDescriptor
*)formRow{
//
判断是不是点击了确定按钮
if([formRow.tag
isEqualToString:@"conform"]
&&
formRow.rowType
==
XLFormRowDescriptorTypeButton){
//获取表单所有到的值
NSDictionary
*values
=
[self
formValues];
NSLog(@"%@",
values);
}
[super
didSelectFormRow:formRow];
}
//重写改该方法
上面的方法就不会调用了
//-(void)tableView:(UITableView
*)tableView
didSelectRowAtIndexPath:(NSIndexPath
*)indexPath{
//
//
NSLog(@"%s",
__func__);
//
//}
@end四、效果图效果图.png五、总结前面两步是官方文档中可以找到的,也很简单,关键在于initializeForm方法中具体构造表单的过程,这里有必要强调几点:1.XLFormViewController实现了UITableViewDataSource,UITableViewDelegate,并且持有一个UITableView,这个从该类的声明可以看出来,所以UITableView、UITableViewDataSource,UITableViewDelegate中的方法都可以正常使用。复制代码代码如下:@interfaceXLFormViewController:UIViewController<UITableViewDataSource,UITableViewDelegate,XLFormDescriptorDelegate,UITextFieldDelegate,UITextViewDelegate,XLFormViewControllerDelegate>2.XLForm将表单抽象为Form,Section,Row三个层次,分别对应三个类XLFormDescriptor
*
form;//form,一个表单只有一个
XLFormSectionDescriptor
*
section;//section,一个表单可能有多个
XLFormRowDescriptor
*
row;
//row,每个section可能有多个row3.每个表单中的具体信息最后都落脚到XLFormRowDescriptor中,通过它可以配置不同样式的表单项,通过构造函数的rowType指定具体的表单类型,该框架提供了非常丰富的rowType,具体可以参考官方文档说明。4.更细化配置表单项就需要借助于XLFormRowDescriptor中的属性进行配置,常用的有@property
(nonatomic,
readonly,
nonnull)
NSMutableDictionary
*
cellConfig;
@property
(nonatomic,
readonly,
nonnull)
NSMutableDictionary
*
cellConfigForSelector;这个配置的时候,往往有同学不知道具体如何才能设置属性,比如怎么设置表单输入框的placeholder?更进一步如何设置placeholder的颜色。其实它用到了KVC,因为它们两个都是UITextField类中的属性,那么直接进入UITextField查找,发现如下信息:@property(nullable,
nonatomic,copy)
NSString
*placeholder;
@property(nullable,
nonatomic,copy)
NSAttributedString
*attributedPlaceholder
NS_AVAILABLE_IOS(6_0);那么设置起来就是[row.cellConfig
setO
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 【正版授权】 ISO/IEC 10164-16:1997 EN Information technology - Open Systems Interconnection - Systems Management: Management knowledge management function
- 【正版授权】 ISO/IEC 10021-2:1990 EN Information Technology - Text Communication - Message-Oriented Text Interchange Systems (MOTIS) - Part 2: Overall Architecture
- 【正版授权】 ISO/ASTM 52943-2:2024 EN Additive manufacturing for aerospace - Process characteristics and performance - Part 2: Directed energy deposition using wire and arc
- 【正版授权】 ISO/ASTM 51707:2005 EN Guide for estimating uncertainties in dosimetry for radiation processing
- 【正版授权】 ISO 9975:1990 EN Round non-alloy steel wires for locked coil mine winding ropes - Specifications
- 【正版授权】 ISO 9969:2007 EN Thermoplastics pipes - Determination of ring stiffness
- 【正版授权】 ISO 9902-7:2001 EN Textile machinery - Noise test code - Part 7: Dyeing and finishing machinery
- 【正版授权】 ISO 9863-1:2005 EN Geosynthetics - Determination of thickness at specified pressures - Part 1: Single layers
- 【正版授权】 ISO 9852:1995 EN Unplasticized poly(vinyl chloride) (PVC-U) pipes - Dichloromethane resistance at specified temperature (DCMT) - Test method
- 【正版授权】 ISO 9806-1:1994 EN Test methods for solar collectors - Part 1: Thermal performance of glazed liquid heating collectors including pressure drop
- 2024年江苏无锡中考英语试卷真题及答案详解(精校打印版)
- 江苏省苏州市常熟市2023-2024学年五年级下学期数学期末检测
- 自行车比赛活动方案7篇
- GB/T 10228-2023干式电力变压器技术参数和要求
- 资产评估收费管理办法中评协[2009]199号
- 国家开放大学电大本科《广告管理》2023-2024期末试题及答案(试卷代号:1346)
- 第三次全国土调查数据库标准
- 水泥罐基础施工方案(终稿)
- 公用食品安全管理台账
- 三位数加三位数连续进位说课稿
- 《食品经营许可证》申请书
评论
0/150
提交评论