0%

UITableview分割线

  1. cell分割线补全

    • 指定cell分割线补全:
      cellForRowAtIndexPath代理中加入如下代码:
      1
      2
      3
      cell.preservesSuperviewLayoutMargins = NO;
      cell.layoutMargins = UIEdgeInsetsZero;
      cell.separatorInset = UIEdgeInsetsZero;
    • 全局cell分割线补全:
      UIControllerView中加入重写如下方法:
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      16
      17
      - (void)viewDidLayoutSubviews {
      if ([self.table respondsToSelector:@selector(setSeparatorInset:)]) {
      [self.table setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
      }
      if ([self.table respondsToSelector:@selector(setLayoutMargins:)]) {
      [self.table setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
      }
      }

      - (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分割线隐藏

    • 指定cell分割线隐藏:
      首先保证指定cell分割线已经补全,然后加入如下代码:

      1
      cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, kDeviceWidth);
    • 全局cell分割先隐藏:

      1
      self.table.separatorStyle = UITableViewCellSeparatorStyleNone;

欢迎关注我的个人微信订阅号,我将不定期分享开发方面的干货。

Jiar's 微信订阅号