Search code examples
iosobjective-ccocoa-touchuitableviewios7

How to remove separator line in iOS 7?


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

enter image description here

enter image description here


Solution

  • 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

    enter image description here