uitableview group的一些问题 (设置两个section之间的距离,设置背景颜色 等)在plain下去掉foot view的粘性

  1.group 时背景颜色设置  

   UIView *backview = [[UIView alloc]init];
  backview.backgroundColor = [UIColor redColor];
  self.tableView.backgroundView = backview;
  self.tableView.backgroundColor = [UIColor redColor];

 或者直接把backgroundView 设置为nil;

 2.在继承UITableViewController下设置tableview 样式

     - (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
self = [super initWithStyle:UITableViewStyleGrouped];
}
return self;
}

 3.设置两个section之间的距离

总之就是通过设置self.tableView.sectionFooterHeight = 0;self.tableView.sectionHeaderHeight = 10; 这两个view的高度来调整section之间的距离 

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

return 20;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

return 20;
}

4.去掉cell边框 

其实跟背景设置一样 在group下 他的BackgroundView并不是空 在plain下是空的  只要按照同样方法设置一个他的BackgroundView就可以去掉他的边框了

UIView *backview = [[ UIView alloc]init];
backview.backgroundColor = [UIColor whiteColor];
[cell setBackgroundView:backview];
[cell setBackgroundColor:[UIColor clearColor]];

5.有时候设置 footview(headerview)不要他跟着section 移动即UItableview header(footer)view黏性(sticky)可以使用以下方法设置

  a. 设置tableview格式为group 这样是不会跟着滑动的

       但是在此种方法下他的headerview 在section=0 的时候 设置header view.height =0 他仍有一个header view 在头部解决方法如下

        在- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
self = [super initWithStyle:UITableViewStyleGrouped];


self.tableView.tableHeaderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, VIEW_WIDTH, 0.01f)];

//设置这个 这个在ios7和以上都可以去掉头部的那个显示 但是在ios 7一下 还要加上  self.tableView.sectionHeaderHeight = 0;


}
return self;
}

然后在-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

if (section == 0 )
{
return 0;
}
//其他地方需要设置header的地方在另外设置就可以了

else
{
return 10;
}}

  b. 在plain下使用以下方法设置

      //去掉UItableview headerview黏性(sticky)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGFloat sectionHeaderHeight = 40;
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);
}
}


   


新手 有啥不对的地方 望指正 谢谢!   

    

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值