How to remove separator line in iOS 7?

只愿长相守 提交于 2019-12-21 21:56:01

问题


First screenshot is iOS7 that not what I want.
First screenshot is iOS6 that what I want.

Tableview's style is plain.
Tableview's separator is none.

And there is a backgroudView of that darkgray color.

I have code like below

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


回答1:


You need to add separate view as a seperator First make tableViews seperator to 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;
    }

Then draw your seperator

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

The output will be something like this




回答2:


This will hide the separator

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

Then add your custom separator imageView in every cell at bottom.




回答3:


Try this

self.tableview.separatorColor = [UIColor clearColor];



回答4:


If you want to remove the separator line of tableviewcell

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

Then add separator line for custom cell

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

Credits go to iPatel Answer



来源:https://stackoverflow.com/questions/21248654/how-to-remove-separator-line-in-ios-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!