美文网首页
UITableView Tips

UITableView Tips

作者: 秋月夜 | 来源:发表于2016-03-02 15:21 被阅读101次

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];
}

相关文章

  • UITableView Tips

    1.cell选中时,去掉选中的灰色背景 或者直接让灰色背景不显示 2.取消cell之间的分隔线 默认是UITabl...

  • UITableView Tips

    UITabelView是iOS开发中最常用, 也是最灵活的控件, 所以, 如何打造出更符合用户体验的tableVi...

  • UITableView Tips

    UITableView是开发中最常用的UI控件, 可是需求和系统的肯定有出入,UI给的设计肯定有不同的地方,这里就...

  • UITableView Tips

    1. 延长分割线 2. 不显示没内容的 Cell 3. 修改 Cell 小对勾的颜色 4. 去掉 SectionH...

  • iOS UITableView Header 不悬停的tip

    UITableView Header 不悬停的tips之一 也可以关注我的个人博客 利用contentInset向...

  • UITableView Tips 高级进阶

    1.cell 高度自适应 // 设置 estimatedRowHeight 大于零 self.tableView...

  • js 兼容 hack

    tips tips tips tips tips

  • UITableView的一个小Tips

    去掉某一行Cell的分割线: Cell.separatorInset = UIEdgeInsetsMake(0...

  • 欢迎来到TableView的天地

    swift UITableView UITableView继承于UIScrollView UITableView的...

  • iOS UITableView基础

    一、UITableView的创建 UITableView *tabelView = [[UITableView a...

网友评论

      本文标题:UITableView Tips

      本文链接:https://www.haomeiwen.com/subject/psynkttx.html