0
我需要的UIView動態大小(它可以方含1個或2個標籤),我做這樣的事情:添加子視圖到UIView後,我可以爲UIView設置框架嗎?
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);
我可以嗎?
當然,實際上只是點擊運行而不是登錄並提出這個問題會更快? – 2012-01-14 17:27:01
嗯,是的,我知道它的工作原理,但我只是想知道這是否是正確的做法... – 2012-01-14 17:29:46