1、tableView header不置顶
-(void)scrollViewDidScroll:(UIScrollView *)scrollView{
if(scrollView == self.tableView) {
// 可以修改为设置的header高度
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);
}
}
}
2、设置tableView的分割线
//UIEdgeInsetsMake(0,左,0,右),按照需求设置
-(void)viewDidLayoutSubviews {
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 12, 0, 12)];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 12, 0, 12)];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsMake(0, 12, 0, 12)];
}
if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
[cell setSeparatorInset:UIEdgeInsetsMake(0, 12, 0, 12)];
}
}
3、滚动tableView 退出键盘
-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView{
[self.view endEditing:YES];
}
4、去除UITableViewStylePlain下,最后一行cell的下划线问题
1、隐藏
// 如果是该分区最后一个cell 隐藏
if(indexPath.row == [tableView numberOfRowsInSection:indexPath.section]-1){
// 1.系统分割线,移到屏幕外(右边距为屏宽)
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, KScreenWidth);
}else{
// 1.设置它的位置(下面设置的为距左12 ,距右12)
cell.separatorInset = UIEdgeInsetsMake(0, 12, 0, 12);
}
2、直接代码隐藏所有的cell下划线,在自定义的UITableViewCell里自己写一个lineView,自己控制线的大小和显示
网友评论