系統(tǒng)的TableviewCell之間是沒有間距的店茶,我們沒法改變,那應(yīng)該怎么來實(shí)現(xiàn)呢屹篓?
方式1:
通過設(shè)置cell的contentView來實(shí)現(xiàn)間接技肩,在cell的contentView的頂部或者底部留下一定的間距,這樣就會(huì)有cell間就有間距的效果酒甸。但是這種方式在cell有點(diǎn)擊效果的時(shí)候魄健,會(huì)很明顯的看出有分層,因?yàn)檫@時(shí)候cell是被點(diǎn)擊的插勤,contentView都會(huì)有系統(tǒng)點(diǎn)擊的陰影效果沽瘦。這種方式在cell左滑刪除革骨,置頂?shù)炔僮鞯臅r(shí)候,左滑出的視圖會(huì)高出一部分(左滑顯示出的高度=(cell的高度-留下的間距高度)+ 留下的間距高度[我們不需要的])
圖片1.png
方式2:
通過分組的方式間接的實(shí)現(xiàn)析恋,每組的Header可以當(dāng)做是cell之間的間距良哲,每組中只有一個(gè)cell(數(shù)據(jù)顯示也會(huì)比較簡單的)。廢話不多說上代碼助隧!
#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;
}
圖片2
每組的Header會(huì)停留在tableview的頂部.gif
但是呢筑凫,這還是會(huì)出現(xiàn)一個(gè)問題,因?yàn)橄到y(tǒng)默認(rèn)分組的時(shí)候每組的Header會(huì)停留在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);
}
}
}
取消UItableview headerview黏性