1、UITextView
//因为继承于UIScrollView 拥有scrollView的所有属性和方法
//placeholder只有UITextField有,UITextView是没有的。(提示文字)
//多行文本框
UITextView * textView = [[UITextView alloc] initWithFrame:CGRectMake(20, 40, self.view.bounds.size.width - 40, 100)];
//设置输入文字
textView.text = @"解放了肯定;
//设置字体
textView.font = [UIFont systemFontOfSize:25];
//设置颜色
textView.textColor = [UIColor redColor];
//设置对齐方式
textView.textAlignment = NSTextAlignmentLeft;
//是否允许编辑
textView.editable = YES;
//设置代理方法
textView.delegate = self;
//inputView(自定义键盘) 可以只设置高度,键盘默认高度216.
2、UITextView 代理
//是否允许开始编辑方法
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView {}
//是否允许结束编辑方法
- (BOOL)textViewShouldEndEditing:(UITextView *)textView {}
//已经开始编辑
- (void)textViewDidBeginEditing:(UITextView *)textView {}
//已经结束编辑
- (void)textViewDidEndEditing:(UITextView *)textView {}
//是否允许文本框文字改变
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {}
//监测文本变化
- (void)textViewDidChange:(UITextView *)textView {
NSLog(@"%@",textView.text);
}
服从数据源 - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {}返回的视图推不上去
但是tableHeaderView 可以推上去
UITableView * tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
//普通
UITableViewStylePlain,
//分组
UITableViewStyleGrouped
//设置数据源
tableView.dataSource = self;
//设置代理
tableView.delegate = self;
//得到所有选中的行数
[self.tableView indexPathsForSelectedRows];
//分区头的高度 默认20
tableView.sectionHeaderHeight = 30;
//分区尾的高度 默认20
tableView.sectionFooterHeight = 30;
//行高,默认行高是44。
tableView.rowHeight = 100;
tableView.backgroundColor = [UIColor grayColor];
//设置背景View
UIImageView * imageView = [[UIImageView alloc] initWithFrame:tableView.bounds];
imageView.image = [UIImage imageNamed:@"baby.jpg"];
tableView.backgroundView = imageView;
//取消选中某一行
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UITableViewCellSeparatorStyleNone 没有线 UITableViewCellSeparatorStyleSingleLine 单行线 UITableViewCellSeparatorStyleSingleLineEtched 被石化的单行线
//线的风格
_tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
//线的内边距
_tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
//索引区域的背景
_tableView.sectionIndexBackgroundColor = [UIColor whiteColor];
//设置索引文字的颜色
_tableView.sectionIndexColor = [UIColor blueColor];
//cell行数小于多少是展示索引
_tableView.sectionIndexMinimumDisplayRowCount = 100;
//选择索引时的背景颜色
_tableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];
//显示索引的题目
- (NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return [self.dataList valueForKey:@"title”];
sep//设置单元格文本
cell.textLabel.text = wechat.title;
//设置单元格 左边视图
cell.imageView.image = [UIImage imageNamed:wechat.icon];
//选中风格
UITableViewCellSelectionStyleNone, //没有点中效果
UITableViewCellSelectionStyleBlue, ==
UITableViewCellSelectionStyleGray, ==
UITableViewCellSelectionStyleDefault
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
//设置cell右端图标
UITableViewCellAccessoryDisclosureIndicator 尖角号
UITableViewCellAccessoryDetailDisclosureButton 圆圈感叹号加尖角号
UITableViewCellAccessoryCheckmark 对号
UITableViewCellAccessoryDetailButton 圆圈感叹号
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//UITableViewCellStyle 单元格风格
UITableViewCellStyleDefault 显示图片,显示辅助图片,显示一行文字
UITableViewCellStyleValue1 显示图片,显示辅助图片,普通文字,描述文字,共占一排
UITableViewCellStyleValue2 不显示图片,显示辅助图片,普通文字,描述文字,共占一排
UITableViewCellStyleSubtitle 显示图片,显示辅助图片,普通文字,描述文字,共占两排
//设置描述文字
cell.detailTextLabel.text = industry.state;
static NSString * identifier = @"cellID";
//从复用池里找对应的cell
UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cellID"];
}
5、UITableViewDataSource 数据源
//cell单元格,IndexPath索引 UITableViewCell是组成UITableView的单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
//Section是几组,Rows多少行(每组内有多少元素),默认情况下只有一个Section.分组的index为0(每一分组多少行)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
//返回分区顶部标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section ;
//返回分区尾部标题
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section ;
//返回单元格的组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
//返回表格视图是否可以编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath ;
//返回表格视图是否可以滚动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath ;
6、UITableViewDelegate 代理方法
//选中某一行
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {}
//设置分区头部视图
//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
//设置分区尾部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {}
//当滚动表格时,这个代理方法,一直调用
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {}
//设置行高方法,如果实现这个代理方法,rowHeight无效,这个主要用于设置可变cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 100;
}
//修改左侧滑动删除方法
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
原文:http://www.cnblogs.com/PSSSCode/p/5272030.html