UITableView Tips

1. 延长分割线

- (void)viewDidLayoutSubviews {
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }
}
- (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];
    }
}

2. 不显示没内容的 Cell

self.tableView.tableFooterView = [[UIView alloc] init];

3. 修改 Cell 小对勾的颜色

 self.tableView.tintColor = [UIColor redColor];

4. 去掉 SectionHeaderView 的悬浮效果

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 60.0;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    // UITableViewStylePlain 样式下,去掉 SectionHeaderView 的悬浮效果
    if (scrollView == self.tableView) {
        CGFloat sectionHeaderHeight = 60.0;
        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);
        }
    }
}

5. 滚动条偏移

self.tableView.scrollIndicatorInsets = UIEdgeInsetsMake(0, 0, 49, 0);

6. 没有置顶

if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)] {
        self.automaticallyAdjustsScrollViewInsets = NO;
}

7. 拖动时收起键盘

self.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;

8. 滑动增加 Cell 动效

// 实际项目中不推荐使用,为了一点点炫,而增加卡顿不值得。
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    cell.alpha = 0.5;
    CGAffineTransform transformScale = CGAffineTransformMakeScale(0.3, 0.8);
    CGAffineTransform transformTranslate = CGAffineTransformMakeTranslation(0.5, 0.6);
    cell.transform = CGAffineTransformConcat(transformScale, transformTranslate);
    [tableView bringSubviewToFront:cell];
    [UIView animateWithDuration:0.5f
                          delay:0
                        options:UIViewAnimationOptionAllowUserInteraction
                     animations:^{
                         cell.alpha = 1;
                         //清空 transform
                         cell.transform = CGAffineTransformIdentity;
                     }
                     completion:nil];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1.cell选中时,去掉选中的灰色背景 或者直接让灰色背景不显示 2.取消cell之间的分隔线 默认是UITabl...
    u14e阅读 144评论 0 0
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,142评论 25 708
  • 人有悲欢离合 月有阴晴圆缺 此事古难全 但愿人长久 千里共婵娟 月圆人团圆 是每一个人的渴求 然而总是有那么些原因...
    丶足迹阅读 192评论 0 0
  • I am very busy but I am happy.(我很忙但我很开心) 文|高慧 早起发动一切机器,做饭...
    白卉阅读 551评论 0 5
  • jdjdbd dhdb dhdvdjd dhd dbd dhd
    洛宁热点阅读 571评论 0 0