iOS Dev
iOS Dev

Reputation: 4248

Wrong UITableView separator color on iOS7

I'm setting UITableView separator color this way:

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.tableView.separatorColor = [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:0.1f];
}

And SOMETIMES on iOS7 my table view separators look different (cells with data and empty cells separators have different alpha I guess), look at attached image: enter image description here

How can I solve this issue?

Upvotes: 2

Views: 6362

Answers (4)

Matheus Abreu
Matheus Abreu

Reputation: 3457

You can set it programatically:

- (void)viewDidLoad {
   [super viewDidLoad];

   [[UITableView appearance] setSeparatorColor:[UIColor redColor]];

}

Upvotes: 1

bhavya kothari
bhavya kothari

Reputation: 7474

You can achieve this visually in storyboard or nib/xib

Put UIImageView at bottom edge of cell and you can set image as per your requirement

STEP 1: Set divider as per image

Set divider as per image

STEP 2: Set Separator style to none

Set Separator style to none

Upvotes: 2

iPatel
iPatel

Reputation: 47059

If you want to remove all cell's separator which has empty content then use following line of code.

self.tableView.tableFooterView = [[UIView alloc] init]; 

in viewDidLoad method.

Other wise set self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; and set your custom UIImagefor separator.

EX:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = @"cell"; //[NSString stringWithFormat:@"S%1dR%1d", indexPath.section, indexPath.row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(cell == nil)
    {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        .
        . // your other code.
        .
        UIImageView *imgLine = [[UIImageView alloc] init];
        imgLine.tag = 101;
        [cell.contentView addSubview: imgLine];
     }

        .
        . // your other code.
        .

     UIImageView *imgLine = (UIImageView *) [cell.contentView viewWithTag:101];
     imgLine.frame =  CGRectMake(5, 69, 310, 1);
     imgLine.image = [UIImage imageNamed:@"queTblLine.png"];

     return cell;
}

And don't forget to set self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

EDITE : Not sure but might be helpful in your case:

set self.tableView.separatorInset = UIEdgeInsetsZero;

Get From question/answer.

Upvotes: 3

Sandeep Agrawal
Sandeep Agrawal

Reputation: 425

Swap the order of the two statements. Set the color first, then the inset:

self.tableView.separatorColor = [UIColor redColor];
self.tableView.separatorInset = UIEdgeInsetsZero;

Upvotes: 2

Related Questions