autoresizingMask只需设置即可更改正在绘制的UILabel的大小

时间:2010-04-26 04:50:23

标签: iphone uiview uitableview uilabel autoresize

我有一些自定义的UITableViewCells是按需编程的,我希望这些可以调整大小。但是,当我将autoresizingMasks添加到单元格中的UILabel时,它们似乎在锚定到左侧时伸展得更宽。

// 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;

因此,当代码的底部部分不存在时,一切都按预期工作,但是当它发生时,许多标签开始从右侧掉落或被拉伸到其中心远离右侧的位置。我忽略了一些简单的事情吗?

0 个答案:

没有答案