在使用IOS的UITableView时,时常会用到它的UITableViewStyleGrouped分组多section属性。而默认的情况下使用该属性后section之间的间距会比较大,看着很不舒服。那么可以通过以下的代理方法配置UITableView各个section的间距。
原理其实很简单,显示效果的各个section间距其实是section头部和底部的组合。配置他们的间距就是配置各个section的头部和底部。具体如下示例:
折叠展开C/C++ Code复制内容到剪贴板
//section头部间距
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 1;//section头部高度
}
//section头部视图
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
view.backgroundColor = [UIColor clearColor];
return [view autorelease];
}
//section底部间距
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 1;
}
//section底部视图
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
UIView *view=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];
view.backgroundColor = [UIColor clearColor];
return [view autorelease];
}
- 浏览: 1836148 次
- 性别:
- 来自: 北京
最新评论
-
wangyudong:
Wisdom RESTClient工具地址更新了哦https: ...
前端模拟POST发送数据-Chrome下的REST Client(接口测试利器) -
wangyudong:
很多REST Client是不支持自动化测试RESTful A ...
前端模拟POST发送数据-Chrome下的REST Client(接口测试利器) -
higkoo:
一个非常棒的系统,要是能支持LDAP等开源认证就完美了。
Cynthia 是个问题管理/BUG管理/任务管理/项目管理系统。 -
寻光之旅:
标签库使用有啥好处呢?
thinkphp 使用标签库的步骤 -
lgdjy123:
Android:TextView属性大全
相关推荐
UITableView的SectionHeader的复用,UITableView的SectionHeader的复用
设置UITableView Section的背景颜色和字体颜色,很详细
作者NSLog-YuHaitao,源码UITableView-section,iOS开发,UITableView中section的展开和收起
UITableView、UITableView基本用法、UITableView详解,UITabelView常用方法
对于ios7,ios8及以上来说,调整UITableView的cell的分割线位置已经是相当不便,因为UITableView内部使用了margin layout. ... // 下面这几行代码是用来设置cell的上下行线的位置 if ([cell respondsToSel
UICollectionView替换UITableView。类似Parallax Header,Sticky Section Header。.zip,uiCollectionView替换uiTableView。更像是视差标题,粘性部分标题。专为iOS 7打造。
主要介绍了ios8 UITableView设置 setSeparatorInset UIEdgeInsetsZero不起作用的解决办法(去掉15px空白间距)的相关资料,需要的朋友可以参考下
UITableView相关操作
UITableView:隐藏删除按钮和设置删除按钮的标题对应的Demo。
简单的UITableView的界面,用于程序中需要设置界面,供新手参考
UITableView 页眉 页脚 Section Demo
UITableView实现横向滑动,源码ScrollLogo,很多朋友可以觉得没有CollectionView方便,但是个人觉得,这个案例还是可以简单方便的,希望大家能够喜欢。
主要介绍了关于iOS利用UITableView设置全屏分隔线的几种方法的相关对比,分析这三种的各自优缺点,并且分享了设置UITableView的单元格分割线离屏幕左右的距离为0的方法,文中通过示例代码介绍的非常详细,需要的朋友...
UITableView Cache - UITableView 缓存
UITableView教材 IPHONE IPAD
IOS UITableView UIcollectionView 结合
UITableView用来以表格的形式显示数据。关于UITableView,我们应该注意: (1)UITableView用来显示表格的可见部分,UITableViewCell用来显示表格的一行。 (2)UITableView并不负责存储表格中的数据,而是仅仅存储...
UITableView 详细讲解
UITableView通过重用单元格来达到节省内存的目的:通过为每个单元格指定一个重用标识符 reuseIdentifier 即指定了单元格的种类 以及当单元格滚出屏幕时 允许恢复单元格以便重用 对于不同种类的单元格使用不同的ID ...
UITableView 缩进 附属视图 Cell Demo