autoresizingMask changes the size of the UILabel being drawn, just by being set

Posted by Kojiro on Stack Overflow See other posts from Stack Overflow or by Kojiro
Published on 2010-04-26T04:50:22Z Indexed on 2010/04/26 4:53 UTC
Read the original article Hit count: 645

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 = carrierField.autoresizingMask;
cField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
dField.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
eField.autoresizingMask = priceField.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?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about autoresize