0
我有一個應用程序,標籤和大文本。我試圖適應標籤的高度,文字是這樣的:UILabel適合文本
UILabel *description = [[UILabel alloc] initWithFrame:CGRectMake(20, sizeInSpik, 275, 0)];
description.text = spik.text;
description.adjustsFontSizeToFitWidth = NO;
description.autoresizingMask = UIViewAutoresizingFlexibleHeight;
[description setFont:[UIFont fontWithName:@"Helvetica Neu" size:13]];
description.textColor = [UIColor blackColor];
description.lineBreakMode = UILineBreakModeWordWrap;
description.numberOfLines = 0;
[description sizeToFit];
// Set the height
CGSize maximumLabelSize1 = CGSizeMake(270,9999);
CGSize titleSize1 = [description.text sizeWithFont:description.font constrainedToSize:maximumLabelSize1 lineBreakMode:description.lineBreakMode];
//Adjust the label the the new height
CGRect newFrame1 = description.frame;
newFrame1.size.height = titleSize1.height;
description.frame = newFrame1;
description.backgroundColor = [UIColor greenColor];
但是,當我實現這個代碼的結果是這樣的:
綠顏色的UILabel背景。
問題是什麼?
PS此外字體大小isnt 13.爲什麼?
你檢查了titleSize1.height是否它不是9999? – Khal 2012-03-13 15:02:04