UITableViewStylePlain與UITableViewStyleGroup樣式

一、UITableViewStylePlain

1.有多段時(shí) 段頭停留(自帶效果)

2.沒有中間的間距和頭部間距(要想有的重寫UITableViewCell \UITableViewHeaderFooterView里面的setFrame方法)

擴(kuò)展:讓段頭不停留(取消粘性效果)

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

CGFloat sectionHeaderHeight = 30;

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);

}

}

// 擴(kuò)展: 頭尾都不懸停

-(void)scrollViewDidScroll:(UIScrollView)scrollView

{

//#warning 改下頭/尾視圖的高度

CGFloat sectionHeaderHeight =20 ;//(頭視圖的高度)

CGFloat sectionFooterHeight = 44;// (尾視圖的高度)

CGFloat f =scrollView.contentSize.height-scrollView.frame.size.height-scrollView.contentOffset.y-sectionFooterHeight;

if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {

scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, -1sectionFooterHeight, 0);

}else if ((scrollView.contentOffset.y>=sectionHeaderHeight)&&(f>=0)) {

scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -1sectionFooterHeight, 0);

}else if ((f>=-1sectionFooterHeight)&&(f<=0)){

scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, -(sectionFooterHeight+f), 0);

}else if (f<-1*sectionFooterHeight){

scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);

}

}

不過在創(chuàng)建tableView時(shí)還得加行代碼

//44為尾視圖高度

tableView.contentInset = UIEdgeInsetsMake(0, 0, -44, 0);

二、UITableViewStyleGroup

注意:去掉頭部和中間間隔

正確的理解方法

1.設(shè)置標(biāo)頭的高度為特小值 (不能為零 為零的話蘋果會(huì)取默認(rèn)值就無法消除頭部間距了)

UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0.001)];

view.backgroundColor = [UIColor redColor];

self.tableView.tableHeaderView = view;

2.寫代理方法(中間的留白其實(shí)是段尾的高度 代理的作用設(shè)置段尾的高度 返回值也不能為0)

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

{

return 0.01f;

}

特殊的處理方法也能實(shí)現(xiàn)該效果

1.? ? self.tableView.contentInset = UIEdgeInsetsMake(-44, 0, 0, 0);

2.重寫UITableViewHeaderFooterView的

-(void)setFrame:(CGRect)frame{

frame.size.height+=10;

[super setFrame:frame];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容