64

I have a UITableViewController initialized with the grouped style and having multiple sections. For one of these sections, I'd like its constituent cells to be completely transparent and have no border. I plan to assign a custom view for every row in this section, but having that custom view surrounded by the grouped table cell looks bad :(

The following makes the background color of a cell black instead of transparent... And I still don't know how to get rid of the border.

cell.backgroundColor = [UIColor clearColor];

Any pointers? Thanks!

2
  • stackoverflow.com/a/5818622/446489 is simplest solution Commented Jun 19, 2012 at 20:50
  • @smilealdway That's not for grouped cells. See Intentss's answer below. Commented Mar 4, 2013 at 20:48

15 Answers 15

159

NOTE: This doesn't appear to be working in iOS7 and above. For iOS7 try this answer.

For iOS6 and below, to remove the grouped background from a cell in a grouped table view cell:

This didn't work

cell.backgroundView = nil; // Did Not Work

This did

cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

If you have moved to ARC (I've heard this works, but haven't tested it)

cell.backgroundView = [UIView new];
Sign up to request clarification or add additional context in comments.

6 Comments

This works for me for iOS 4.3.3 too and i prefer this solution, because you can remove the border for each cell individually instead of removing it for all cells of the table view.
Also set the cell.selectedBackgroundView using the same otherwise it may highlight.
[cell setBackgroundColor:t.best5bgColor];
@RyanRomanchuk I've found a way that works in iOS 7: stackoverflow.com/a/19220030/1372503
Thanks a lot buddy, wish I found this earlier. For iOS 7, I think it doesn't add any style for grouped tables.
|
39

You have to actually set

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

to remove the border of cells.

1 Comment

The question is asking about grouped tables. tableView.separatorStyle = UITableViewCellSeparatorStyleNone doesn't work on grouped tables.
37

The following hack works in iOS 7 – for now. :)

Subclass UITableViewCell, and use this cell for the section that shouldn't have separators.
Override the addSubview method in your cell subclass:

-(void)addSubview:(UIView *)view
{
    // The separator has a height of 0.5pt on a retina display and 1pt on non-retina.
    // Prevent subviews with this height from being added. 
    if (CGRectGetHeight(view.frame)*[UIScreen mainScreen].scale == 1)
    {
        return;
    }

    [super addSubview:view];
}

5 Comments

Note also that this doesn't work on iOS6, so for iOS6 cell.backgroundView = [UIView new]; is still required.
@Pin The separators seem to be separate subviews in iOS 7. This code simply prevents them from being added to the cell. It's not very sophisticated though. :)
in iPad height is 1 , iPhone height is 0.5
@RanyA.Ishak It's actually not the device type that makes the difference but the screen resolution. I've modified the code to handle both retina and non-retina displays.
Works for iOS9 as well. Brilliant hack!
23

This is what worked for with having a Grouped style table

[tableView setSeparatorColor:[UIColor clearColor]];

5 Comments

This solution worked for me! And I think this is a better solution than "cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];" from performance standpoint. I am using Grouped style table, iOS 5.1. Thanks
I don't know what kind of performance you are talking about, generally setting anything to [UIColor clearColor] is bad idea when it comes to graphics performance because it's a non-opqaue layer that forces the GPU to do transparency blending.
if I use the above with a grouped tableview, I get that the overall border of the table is gone, which is what I expected. It seems that separator color == table border.
The other nice thing about this answer is that you can use it in IB too, so you can see your cell as it is meant to look.
But this removes the separator from the whole table view, not from a single section.
19

This code worked for me :)

[self.tableView setSeparatorColor:[UIColor clearColor]];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

Comments

2

Set the backgroundView of the cell to nil. For a grouped table, the cell image is part of that view.

1 Comment

Didn't work for iOS 4.3.3, or maybe I don't understand what you are talking about.
1
cell.backgroundColor = [UIColor clearColor];

cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

Comments

1

Try using tableView.separatorColor = [UIColor clearColor];

And, don't use tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

I tested with both, if style is none, making the section borders invisible is not working, but instead just change its color, and section border will appear to be none.

iOS seems to be differentiating making an object none and making an object transparent

3 Comments

The question was how to remove the border, not the separator.
@JohanKarlsson Though property is separatorColor, it affects the border of Grouped style for tableView Try it yourself~
I have tried it. I know it affects both. But nothing in your answer explains this ;-)
1
cell.backgroundView = [UIView new];

Works like a charm! Tested! iOS6

Comments

1

As of iOS 8, setting the separator attribute to none works as well.

Get rid of cell border

Comments

0

Setting a content view also gets rid of the border. Set your custom view to cell.contentView.

Comments

0

The easiest way to remove cell borders from a section of grouped-style UITableView:

[tableViewOutlet setBackgroundView:nil];

in the viewDidLoad method.

Comments

0
 UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
 backView.backgroundColor = [UIColor clearColor];
 cell.backgroundView = backView;
 cell.backgroundColor = [UIColor clearColor];
 [cell.contentView addSubview:imageView];

Comments

0

If you have a custom UITableCellView then you can add the following method to your view to remove the background view.

- (void)setBackgroundView:(UIView *)backgroundView
{
    // We don't want background views for this cell.
    [super setBackgroundView:nil];
}

Comments

0

I just thought I would convert my comment to @Intentss into an answer, because it maybe useful for those, using his solution.

Using iOS6.1 with a grouped UITabelView, using ARC:

[tableView setSeparatorColor:[UIColor clearColor]];

Does not work

cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];

Does work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.