设置tableView的页眉和页脚
2016-07-19 14:21
375 查看
(1).自定义页眉和页脚时,要先注册
//注册页眉
[_tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"header"];
//注册页脚
[_tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"footer"];
(2).在UITableViewDelegate的代理方法中,分别选择-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 和-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section两个方法
//自定义页眉
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSDictionary *bigDic = bigArr[section];
UITableViewHeaderFooterView *headerView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"header"];
//商店图标
UIImageView *iconImage = [[UIImageView alloc] initWithFrame:CGRectMake(SP_W(10), SP_W(10), SP_W(20), SP_W(20))];
iconImage.backgroundColor = [UIColor redColor];
[headerView addSubview:iconImage];
//商店名称
UILabel *shopLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(iconImage.frame) + SP_W(5), SP_W(5), SP_W(100), SP_W(30))];
shopLabel.text = bigDic[@"tc_name"];
shopLabel.font = [UIFont systemFontOfSize:15];
[headerView addSubview:shopLabel];
return headerView;
}
//自定义页脚
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
NSDictionary *bigDic = bigArr[section];
UITableViewHeaderFooterView *footerView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"footer"];
//合计数量
UILabel *sumAmountLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 8 * 4,SP_W(5), WIDTH / 8 * 3, SP_W(30))];
[footerView addSubview:sumAmountLabel];
return footerView;
}
(3).设置页眉和页脚的高度
//返回页眉的高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 40;
}
//返回页脚的高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
NSDictionary *bigDic = bigArr[section];
return 90;
}
(4).在布局tableview的代码中也要设置页眉和页脚的高度
_tableView.sectionHeaderHight = 40;
_tableView.sectionFooterHight = 90;
//注册页眉
[_tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"header"];
//注册页脚
[_tableView registerClass:[UITableViewHeaderFooterView class] forHeaderFooterViewReuseIdentifier:@"footer"];
(2).在UITableViewDelegate的代理方法中,分别选择-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 和-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section两个方法
//自定义页眉
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSDictionary *bigDic = bigArr[section];
UITableViewHeaderFooterView *headerView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"header"];
//商店图标
UIImageView *iconImage = [[UIImageView alloc] initWithFrame:CGRectMake(SP_W(10), SP_W(10), SP_W(20), SP_W(20))];
iconImage.backgroundColor = [UIColor redColor];
[headerView addSubview:iconImage];
//商店名称
UILabel *shopLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(iconImage.frame) + SP_W(5), SP_W(5), SP_W(100), SP_W(30))];
shopLabel.text = bigDic[@"tc_name"];
shopLabel.font = [UIFont systemFontOfSize:15];
[headerView addSubview:shopLabel];
return headerView;
}
//自定义页脚
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
NSDictionary *bigDic = bigArr[section];
UITableViewHeaderFooterView *footerView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:@"footer"];
//合计数量
UILabel *sumAmountLabel = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH / 8 * 4,SP_W(5), WIDTH / 8 * 3, SP_W(30))];
[footerView addSubview:sumAmountLabel];
return footerView;
}
(3).设置页眉和页脚的高度
//返回页眉的高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 40;
}
//返回页脚的高度
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
NSDictionary *bigDic = bigArr[section];
return 90;
}
(4).在布局tableview的代码中也要设置页眉和页脚的高度
_tableView.sectionHeaderHight = 40;
_tableView.sectionFooterHight = 90;
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- div+css如何实现页脚的置底
- Bootstrap 粘页脚效果
- 在ASP.NET 2.0中操作数据之十五:在GridView的页脚中显示统计信息
- JQuery Mobile实现导航栏和页脚
- 讲解iOS开发中基本的定位功能实现
- iOS中定位当前位置坐标及转换为火星坐标的方法
- js判断客户端是iOS还是Android等移动终端的方法
- iOS应用开发中AFNetworking库的常用HTTP操作方法小结
- iOS应用中UISearchDisplayController搜索效果的用法
- iOS App开发中的UISegmentedControl分段组件用法总结
- IOS开发环境windows化攻略
- iOS应用中UITableView左滑自定义选项及批量删除的实现
- iOS中UIAlertView警告框组件的使用教程