AutoresizingMask resizes the UILabel's drawing by simply setting

I have some custom UITableViewCells made programmatically as needed, I want them to be resized. However, when I add autoresizingMasks to UILabels in the cells, they all appear wider when anchored 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 part of the code doesn't exist, everything works as expected, but when it does, many labels start to fall off the right side or stretch to where their centers are far to the right. Can I miss something simple?

+2


a source to share





All Articles