Yar
Yar

Reputation: 7457

Different UITableViewCell types alignment

I have two types of UITableViewCell on top of each other. The first one is UITableViewCellAccessoryDisclosureIndicator and the bottom one is UITableViewCellAccessoryNone:

if(someCondition)
{
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else
{            
    cell.accessoryType = UITableViewCellAccessoryNone;
    // this didn't work
    // cell.layoutMargins = UIEdgeInsetsMake(0.0, 0, 0.0, 10.0);
}

What I'm trying to do is to move the two labels of the bottom cell to the left , so the right edge of both cells become aligned. I tried to do this by adding a layoutMargins to the bottom cell but it didn't work. Any idea how to do this?

Upvotes: 1

Views: 118

Answers (1)

rmaddy
rmaddy

Reputation: 318774

Set the bottom cell's accessoryView to an empty view with the needed width.

if(someCondition)
{
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.accessoryView = nil;
}
else
{            
    cell.accessoryType = UITableViewCellAccessoryNone;
    // Adjust the width value as needed
    cell.accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 25, 5)];
}

Upvotes: 2

Related Questions