UITableView+UITableViewStyleGrouped 处理section之间间隙
2016-07-14 00:00
501 查看
摘要: 为了了解回顾uitableview,把今天遇到的一些小问题及处理方法裂了出来,加强一下记忆。
这样初始化的tableview的样式是这样的:如下:
style设置为UITableViewStyleGrouped时header和footer不会悬浮在视图上,设置为UITableViewStylePlain就会悬浮。
然后我设置了每个section的高:
红框的区域是多出来的,我把header的高设置为30,header上的View高也是30;
但是会多出来,那片就是footer的区域,把他的高设置为0.1就行了(设置为0不行)
或者在初始化tableview时加一句
[[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped]
这样初始化的tableview的样式是这样的:如下:
style设置为UITableViewStyleGrouped时header和footer不会悬浮在视图上,设置为UITableViewStylePlain就会悬浮。
然后我设置了每个section的高:
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if(section==0){ //让第一个不显示 return 0.1;} return 30; } -(UIView* )tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ if (section==0) { return nil; } UILabel *lb=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]; lb.text=[NSString stringWithFormat:@"%ld",section]; lb.backgroundColor=[UIColor greenColor]; return lb; }
红框的区域是多出来的,我把header的高设置为30,header上的View高也是30;
但是会多出来,那片就是footer的区域,把他的高设置为0.1就行了(设置为0不行)
//header的高 -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { if(section==0){ return 0.1;} return 30; } //footer的高 必须在这设置footer的高不然tableview的尾部会多出一块 -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{ if (section==9) { return 0.1; } return 0.1; } //header的View -(UIView* )tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{ if (section==0) { return nil; } UILabel *lb=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 30)]; lb.text=[NSString stringWithFormat:@"%ld",section]; lb.backgroundColor=[UIColor greenColor]; return lb; }
或者在初始化tableview时加一句
//高设置为0.1可以;设置为0不行 self.tableview.tableFooterView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 0.1)];
相关文章推荐
- 克隆虚拟机重启服务时 Error:No suitable device found: no device found for connection "System eth0"
- Qt Quick Controls 和 Qt Quick的区别
- UITableView 重用池原理
- Could Not Get the Value for Parameter compilerId for Plugin Execution
- UITableView设置表头后向上拉,表头的解决办法
- 一次$_REQUEST的count参数异常BUG排查
- 在win7上安装ubuntu12.04双系统(uefi主板)
- F - Longest Ordered Subsequence
- UGUI之修改Text字间距
- Easyui 一些应用
- webpack + vue.js + vue route
- 瀑布流UICollectionViewFlowLayout/UICollectionViewLayout
- LeetCode 374. Guess Number Higher or Lower
- 详解Autolayout 设置UITableViewCell 高度问题
- 334. Increasing Triplet Subsequence
- UItableView动态刷新数据 --------->>>组、行动态加载
- leetcode之Guess Number Higher or Lower
- NSOperationQueue
- SqueezeNet: AlexNet-level accuracy with 50x fewer parameters and <0.5MB model size
- iOS开发中的错误整理,iOS9之后的UIWindow(TopWindow)以及UIWindow与statusBar的关系