我在爲兩個不同字符串獲取正確幀時遇到了一個問題。我通過下面的代碼運行兩個字符串:設置後標籤大小發生變化,具體取決於字符串
UILabel *myLabel = [[[UILabel alloc] initWithFrame:CGRectZero] autorelease];
myLabel.lineBreakMode = UILineBreakModeWordWrap;
myLabel.numberOfLines = 2;
myLabel.textAlignment = UITextAlignmentCenter;
myLabel.font = [UIFont boldSystemFontOfSize:11];
myLabel.text = @"About Stores"
myLabel.text = @"About Rivers"
CGSize myLabelSize = CGSizeMake(70,28);
[myLabel sizeWithFont:myString.font // <-- One of two strings
constrainedToSize:aLabelSize
lineBreakMode:UILineBreakModeWordWrap];
結果爲myString1
=>寬度:70,高度:28
結果爲myString2
=>寬度:70,高度:14
爲什麼有這裏有什麼不同?
什麼是myString.font?什麼是標籤大小?你在第二行缺少一個分號。 – titaniumdecoy 2011-05-24 16:54:15
@Jason:更新了我的問題。它是一個UILabel。 – Abhinav 2011-05-24 17:27:17