OC_实现UITableviewCell之间的间距
来源:互联网 发布:嵌入式linux启动 编辑:程序博客网 时间:2024/05/16 19:52
系统的TableviewCell之间是没有间距的,我们没法改变,那应该怎么来实现呢?
方式1:
通过设置cell的contentView来实现间接,在cell的contentView的顶部或者底部留下一定的间距,这样就会有cell间就有间距的效果。但是这种方式在cell有点击效果的时候,会很明显的看出有分层,因为这时候cell是被点击的,contentView都会有系统点击的阴影效果。这种方式在cell左滑删除,置顶等操作的时候,左滑出的视图会高出一部分(左滑显示出的高度=(cell的高度-留下的间距高度)+ 留下的间距高度[我们不需要的])
方式2:
通过分组的方式间接的实现,每组的Header可以当做是cell之间的间距,每组中只有一个cell(数据显示也会比较简单的)。废话不多说上代码!
#pragma mark - UITableViewDataSource,UITableViewDelegate- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 10;}- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 10;}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 1;}- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return 100;}
但是呢,这还是会出现一个问题,因为系统默认分组的时候每组的Header会停留在tableview的顶部,这要怎么处理呢?
//去掉UItableview headerview黏性(sticky)- (void)scrollViewDidScroll:(UIScrollView *)scrollView { if (scrollView == self.tableView) { CGFloat sectionHeaderHeight = 10; //sectionHeaderHeight if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) { scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0); } else if (scrollView.contentOffset.y >= sectionHeaderHeight) { scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0); } }}
0 0
- OC_实现UITableviewCell之间的间距
- 计算UITableViewCell之间的间距
- 设置自定义UITableViewCell之间的间距
- 设置自定义UITableViewCell之间的间距
- 计算UITableViewCell之间的间距(完美版)
- 设置自定义UITableViewCell之间的间距
- iOS-OC-设置UITableViewCell之间的间距
- iOS-OC-设置UITableViewCell之间的间距
- OC 如何设置UITableViewCell之间的间距
- iOS-OC-设置UITableViewCell之间的间距(推荐第四种)
- iOS开发之有间距的UITableViewCell
- iOS开发之有间距的UITableViewCell
- iOS开发之有间距的UITableViewCell
- 自定义带有cell间距的UITableViewCell
- ViewPager中图片于图片之间的间距实现效果
- 字体之间的间距调整
- 设置tableViewCell之间的间距
- 消除img之间的间距
- JZOJ4444
- Oracle学习笔记(十四)——数据库管理
- copy与mutableCopy
- 记录下而已
- OpenCV3.0或OpenCV3.1的SVM操作
- OC_实现UITableviewCell之间的间距
- oracle 恢复到之前某个时间点
- Displaying Graphics with OpenGL ES(三)——Drawing Shapes
- jquery中mouseover和mouseout以及mouseenter和mouseleave的区别
- Java--计算中英文长度的若干种方法
- Google Guava之--cache
- 求两个数组中都出现的元素
- IOS研究之iOS7适配的使用详细说明
- 如何实现云时代的高效运维?