UITableView的一些细节技巧
2015-05-21 15:54
363 查看
1.UITableViewStyleGrouped 类型更改分组的间隔,用下面两个方法就可以调节。
//设置每个分组的Header的大小
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10;
}
//设置每个分组的Footer的大小(如果只是设置大小,设置header的大小,footer返回大于0)
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1;
}
注意:返回值设置不能设置成为0,因为0被认为默认,所以如果写0,是没有任何效果的;
2.更改tableView右侧索引的颜色等,方法是iOS7的,适配低版本要加版本判断
if ([self.addressBookTableView respondsToSelector:@selector(setSectionIndexColor:)]) {
self.addressBookTableView.sectionIndexBackgroundColor = [UIColor clearColor];//修改右边索引的背景色
self.addressBookTableView.sectionIndexColor = [UIColor grayColor];//修改右边索引字体的颜色
self.addressBookTableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];//修改右边索引点击时候的背景色
}
3.UITableViewStylePlain 类型带分组的,比如通讯录页面A-Z分组的,最后一条数据的分割线不是从顶点开始的,可以在storyboard里tableView里拖一个1像素高度footView,这样它就认为下面还有布局内容,分割线就从顶点开始了,代码里写的就初始化一下tableFootView,一个意思。
4.可以设置分割线的位置,iOS7,iOS8两个系统都起作用。
-(void)viewDidLayoutSubviews
{
if ([self.settingTableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.settingTableView setSeparatorInset:UIEdgeInsetsMake(0,15,0,0)];
}
if ([self.settingTableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.settingTableView setLayoutMargins:UIEdgeInsetsMake(0,15,0,0)];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsMake(0
4000
,15,0,0)];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsMake(0,15,0,0)];
}
}
//设置每个分组的Header的大小
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 10;
}
//设置每个分组的Footer的大小(如果只是设置大小,设置header的大小,footer返回大于0)
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1;
}
注意:返回值设置不能设置成为0,因为0被认为默认,所以如果写0,是没有任何效果的;
2.更改tableView右侧索引的颜色等,方法是iOS7的,适配低版本要加版本判断
if ([self.addressBookTableView respondsToSelector:@selector(setSectionIndexColor:)]) {
self.addressBookTableView.sectionIndexBackgroundColor = [UIColor clearColor];//修改右边索引的背景色
self.addressBookTableView.sectionIndexColor = [UIColor grayColor];//修改右边索引字体的颜色
self.addressBookTableView.sectionIndexTrackingBackgroundColor = [UIColor clearColor];//修改右边索引点击时候的背景色
}
3.UITableViewStylePlain 类型带分组的,比如通讯录页面A-Z分组的,最后一条数据的分割线不是从顶点开始的,可以在storyboard里tableView里拖一个1像素高度footView,这样它就认为下面还有布局内容,分割线就从顶点开始了,代码里写的就初始化一下tableFootView,一个意思。
4.可以设置分割线的位置,iOS7,iOS8两个系统都起作用。
-(void)viewDidLayoutSubviews
{
if ([self.settingTableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.settingTableView setSeparatorInset:UIEdgeInsetsMake(0,15,0,0)];
}
if ([self.settingTableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.settingTableView setLayoutMargins:UIEdgeInsetsMake(0,15,0,0)];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsMake(0
4000
,15,0,0)];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsMake(0,15,0,0)];
}
}
相关文章推荐
- Swift开发UITableView常用的一些细节知识点介绍
- Swift开发UITableView常用的一些细节知识点介绍
- 提高UITableView滚动流畅性的一些技巧
- iOS应用开发中UITableView的分割线的一些设置技巧
- iOS开发-UITableView及其Cell的一些细节
- UItableView编辑的使用edit, UItableView的一些常用方法
- [iOS]tableView 一些技巧
- 2015/10/4 iOS 笔记 细节 简单-代理过程 UITableView
- UITableView 的一些小知识
- ios7开发的一些技巧 textfiled tableview重用 idfa 证书
- UITableView细节.txt
- iOS UITableView的一些常用属性,方法
- UITableView的使用规则和技巧等
- 详细整理:UITableView优化技巧
- UITableView优化技巧
- 详细整理:UITableView优化技巧
- 关于UITableView及dequeueReusableCellWithIdentifier的一些理解
- 个人总结的一些JavaScript技巧、实用函数、简洁方法、编程细节
- Objective-C --- - UITableView 二 对一进行一些属性补充(梳理总结)
- UITableView优化技巧4