tableView有兩種style:UITableViewStylePlain,? ? ? ? ? // 常規(guī)普通的展現(xiàn)方式
1.有多段時 段頭停留(自帶效果)
2.沒有中間的間距和頭部間距(要想有的重寫UITableViewCell \UITableViewHeaderFooterView里面的setFrame方法)
擴展:讓段頭不停留(取消粘性效果)
- (void)scrollViewDidScroll:(UIScrollView*)scrollView{? ? if (scrollView== self.tableView)? ? {? ? ? ? CGFloat sectionHeaderHeight =20;//這個高度就是你的header的高度
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);}? ? }}
UITableViewStyleGrouped? ? ? ? // 適用于分組
沒有懸浮的效果,頭部和每個secontion 中間會有間距,可自己進行設置.如果想要去掉頭部和中間間隔
在使用的時候回發(fā)現(xiàn),在代理方法里面-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01;
}
頭部仍然會有一段間距,這個間距實際上是tableView.tableHeaderView的高度帶來的,解決方法如下:
1.設置標頭的高度為特小值 (不能為零 為零的話蘋果會取默認值就無法消除頭部間距了)
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.001)];
view.backgroundColor = [UIColorredColor];
self.tableView.tableHeaderView = view;
2.寫代理方法(中間的留白其實是段尾的高度 代理的作用設置段尾的高度 返回值也不能為0)
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.01f;
}
特殊的處理方法也能實現(xiàn)該效果
1. ? ?self.tableView.contentInset = UIEdgeInsetsMake(-44, 0, 0, 0);
2.重寫UITableViewHeaderFooterView的
-(void)setFrame:(CGRect)frame{
frame.size.height+=10;
[super setFrame:frame];
}
承接APP,小程序,公眾號開發(fā). 性價比高.+V信:17723566468 ?有單子也可找我一起做哦