views:

519

answers:

0

I have some custom UITableViewCells that are made programmatically as needed, I want these to resize. However, when I add autoresizingMasks to the UILabels in the cells, they all seem to stretch wider while anchoring to the left side.

// This works fine
UILabel *aField = [[UILabel alloc] initWithFrame:CGRectMake(60, 2, tableView.frame.size.width - 83, 21)];
UILabel *bField = [[UILabel alloc] initWithFrame:CGRectMake(60, 20, tableView.frame.size.width - 154, 21)];
UILabel *cField = [[UILabel alloc] initWithFrame:CGRectMake(0, 2, tableView.frame.size.width, 21)];
UILabel *dField = [[UILabel alloc] initWithFrame:CGRectMake(tableView.frame.size.width - 116, 11, 93, 21)];
UILabel *eField = [[UILabel alloc] initWithFrame:CGRectMake(tableView.frame.size.width - 116, 11, 93, 21)];

// But when I add this, it draws like the tableview is actually much wider than it really is
aField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
bField.autoresizingMask = aField.autoresizingMask;
cField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
dField.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
eField.autoresizingMask = dField.autoresizingMask;

So when the bottom section of code doesn't exist, everything works as expected, but when it does, a lot of the labels start falling off the right side or being stretched to where their centers are far to the right. Am I overlooking something simple?