【问题标题】:How to remove separator line in iOS 7?如何在 iOS 7 中删除分隔线?
【发布时间】:2014-02-10 11:42:23
【问题描述】:

第一个屏幕截图是 iOS7,这不是我想要的。
第一张截图是我想要的iOS6。

Tableview 的风格很朴素。
Tableview 的分隔符是 none。

还有那个深灰色的背景视图。

我有如下代码

if ([tableView respondsToSelector:@selector(setSeparatorInset:)])
    {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }

cell.backgroundView = [[UIImageView alloc] initWithImage:[ [UIImage imageNamed:@"icon_bg_box.png"] stretchableImageWithLeftCapWidth:0.0 topCapHeight:5.0] ];

【问题讨论】:

    标签: ios objective-c cocoa-touch uitableview ios7


    【解决方案1】:

    您需要添加单独的视图作为分隔符 首先将 tableViews 分隔符设为 none

    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
            UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    
        [cell addSubview:[self drawSeparationView:(indexPath.row)]];
          return cell;
        }
    

    然后画你的分隔符

    - (UIView*)drawSeparationView:(NSInteger)itemNo {
        UIView *view = [[UIView alloc] init];
        view.frame = CGRectMake(0, 0, self.tableView.frame.size.width, cellHeight);
    
        UIView *upperStrip = [[UIView alloc]init];
        upperStrip.backgroundColor = [UIColor colorWithWhite:0.138 alpha:1.000];
        upperStrip.frame = CGRectMake(0, 0, view.frame.size.width, 2);
        [view addSubview:upperStrip];
    
        UIView *lowerStrip = [[UIView alloc]init];
        lowerStrip.backgroundColor = [UIColor colorWithWhite:0.063 alpha:1.000];
        lowerStrip.frame = CGRectMake(0, cellHeight-2, view.frame.size.width, 2);
    
        [view addSubview:lowerStrip];
        return view;
    }
    

    输出会是这样的

    【讨论】:

      【解决方案2】:

      这将隐藏分隔符

      self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
      

      然后在底部的每个单元格中添加自定义分隔符 imageView。

      【讨论】:

        【解决方案3】:

        试试这个

        self.tableview.separatorColor = [UIColor clearColor];
        

        【讨论】:

          【解决方案4】:

          如果要去掉tableviewcell的分隔线

          self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
          

          然后为自定义单元格添加分隔线

          UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 1)];/// change size as you need.
          separatorLineView.backgroundColor = [UIColor grayColor];// you can also put image here
          [cell.contentView addSubview:separatorLineView];
          

          致谢 iPatel Answer

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-01-21
            • 2020-05-13
            • 2017-03-12
            • 2011-02-05
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多