-2

how to change Separator Style for UITableView expandable cell. I am using Custom Tableview Class for that.

Dhaval Tannarana
  • 181
  • 1
  • 2
  • 9
  • 1
    Can not understand question properly. please add more detail. you can set separator style using `yourTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine` or `UITableViewCellSeparatorStyleNone` or `UITableViewCellSeparatorStyleSingleLineEtched` – ChintaN -Maddy- Ramani Dec 30 '14 at 11:46
  • 3
    Please search before you post your questions. Your question is a very basic task which was answered very often on this site. For example have a look at this: [Custom Separator](http://stackoverflow.com/questions/1374990/how-to-customize-tableview-separator-in-iphone) – dehlen Dec 30 '14 at 11:46

2 Answers2

0
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine];
Abhishek Sharma
  • 3,283
  • 1
  • 13
  • 22
0

Potentially add a UIView as a separator of your own that has an autoresizing mask set to keep it stuck to the bottom.

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

Then in your custom UITableViewCell subclass

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        self.backgroundColor = [UIColor myColour]; // do cell setup in here


        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0.0f, self.contentView.bounds.size.height - 1.0f, self.contentView.bounds.size.width, 1.0f)];
        lineView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
        lineView.backgroundColor = [UIColor myOtherColour];

        [self.contentView addSubview:lineView];
}

return self;

}

If you really want to do it in cellForRowAtIndexPath you can, but I wouldn't recommend it

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
      static NSString *CellIdentifier = @"Cell";

      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];

      if (!cell)
      {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier: CellIdentifier];

        cell.backgroundColor = [UIColor myColour]; // do cell setup in here


        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0.0f, cell.contentView.bounds.size.height - 1.0f, cell.contentView.bounds.size.width, 1.0f)];
        lineView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
        lineView.backgroundColor = [UIColor myOtherColour];

        [cell.contentView addSubview:lineView];
      }

  // rest of your cell for row code here
Magoo
  • 2,552
  • 1
  • 23
  • 43