我需要动态大小的UIView(它可以包含1或2个标签),我这样做:
float nextY = 0.0f;
float labelHeight = 20.0f;
UIView *tempView = [[UIView alloc] initWithFrame:CGRectZero];
UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, nextY, 100.0f, labelHeight)];
label1.text = @"Test 1";
[tempView addSubview:label1];
nextY += labelHeight;
if (something == YES)
{
UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, nextY, 100.0f, labelHeight)];
label1.text = @"Test 2";
[tempView addSubview:label2];
nextY += labelHeight;
}
tempView.frame = CGRectMake(0.0f, 0.0f, 100.0.f, nextY);
我还好吗?
答案 0 :(得分:0)
你在做什么是有效的。如果在子视图上设置自动调整遮罩,则在更改超视图的帧时,系统还将调整子视图的帧。