
在ios7以后,UITableViewCell左側(cè)會有默認(rèn)15像素的空白,有時候我們要求cell的分割線從邊界開始,就需要重新設(shè)置分割線。
- 在iOS7中,可以通過設(shè)置
setSeparatorInset:UIEdgeInsetsZero的方法修改。 - 在iOS8以后,上面的方法會不起作用,需要用下面的方法設(shè)置:
- 首先在viewDidLoad方法加入以下代碼:
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
} - 然后在UITableView的代理方法中加入以下代碼
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
- 首先在viewDidLoad方法加入以下代碼:
去掉多余cell
[tableView setTableFooterView:[UIView new]];
去掉section在tableview中的黏性
- (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);
}
}